This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Servlets and the fly likes Can a servlet listen to something else than http port.. and talk other protocols Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Can a servlet listen to something else than http port.. and talk other protocols" Watch "Can a servlet listen to something else than http port.. and talk other protocols" New topic
Author

Can a servlet listen to something else than http port.. and talk other protocols

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi there,
a very greenhorn question:
Can I design/code an servlet, that - once it's loaded -- listens to a different http port (e.g 25/SMTP or pserver and talk in that protocol? Could someone point to sample code?
THX!
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
A servlet can do just about anything any other class can do - that does not mean it is a good idea. The port and protocol on which your servlet sees requests and responses is fixed by the servlet engine.
You would get better results and not get tangled up in problems of Threading, etc. if you created a separate class (possibly a separate application) to do work on other ports and protocols and have a servlet that can talk to that other class when needed.
Bill
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
...created a separate class (possibly a separate application) to do work on other ports and protocols and have a servlet that can talk to that other class when needed...
Bill

Thx Bill for the answer. Did I get it right:
- I create a standalone Java app that handles my port xyz and then talks to the servlet or the servlet talks to it. For the later a subscriber pattern seems appropriate?
To twist the question a bit: If the servlet can listen on port 80 (or 443), but the "talk" coming in is not http but the protocol/syntax used by a CVS client. Would that be a feasible use for an servlet?
Thx
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can a servlet listen to something else than http port.. and talk other protocols