• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Tomcat and sockets for receiving and transmiting data

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 :-)
 
Marshal
Posts: 28295
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Saloon Keeper
Posts: 28117
198
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Where does a nanny get ground to air missles? Protect this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic