• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Tomcat and sockets for receiving and transmiting data

 
gabi gaminde
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am new to socket programing and I have some trouble understanding how to use them with Tomcat. Let me explain it in more detail. I want to be able to send some messages from my web application to other application that is not running on Tomcat but in the same network. I have to send and receive messages from and to this application. Can I use port 8080 to do so? (the one that Tomcat is using) How can I capture messages sent from the other application? I think Tomcat is alredy a server so I don't need to build a server class for that. In fact I've tried it but it seems to block my application.

Can someone give me a hint? Maybe I am talking nonsense and I must use another port?

Thanks in advance :-)
 
Paul Clapham
Sheriff
Pie
Posts: 20971
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Of course you can send messages to that server. You would do that exactly the same way as if you were doing it from an ordinary Java application. The fact that your code would be running in Tomcat is just about irrelevant. Likewise it's irrelevant that Tomcat happens to be a server. As for what port to use, you would use the port which that server is listening at.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18098
50
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Only one application at a time can use a specific port number on a machine. But like Paul said, the port number you use is the one that the target server is listening on, not the one that Tomcat is listening on.

If some other machine is listening on its port 8080, that's no problem. If you tried to start another server listening on port 8080 on the same machine that's running Tomcat, the OS wouldn't let it, since port 8080's already in use. Or, for apps like Tomcat, the app itself may come up, but it won't listen on the occupied port. (Tomcat displays a "port in use" message in the log).
 
gabi gaminde
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Many thanks for the answers The problem I have is that when I try to start a listening port in the webapp it blocks it. I try to use port 7777 (as on the code example I have) and the server blocks on startup. I have a listener class (that I configure in the Web.xml file) that tries to open a port for listening.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic