aspose file tools*
The moose likes Tomcat and the fly likes Tomcat and sockets for receiving and transmiting data Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Tomcat and sockets for receiving and transmiting data" Watch "Tomcat and sockets for receiving and transmiting data" New topic
Author

Tomcat and sockets for receiving and transmiting data

gabi gaminde
Greenhorn

Joined: Jul 23, 2011
Posts: 4
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
Bartender

Joined: Oct 14, 2005
Posts: 18564
    
    8

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

Joined: Jun 25, 2001
Posts: 16054
    
  21

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).


Customer surveys are for companies who didn't pay proper attention to begin with.
gabi gaminde
Greenhorn

Joined: Jul 23, 2011
Posts: 4
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Tomcat and sockets for receiving and transmiting data