Two Laptop Bag*
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 Android Security Essentials Live Lessons this week in the Android 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: 12761
    
    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
 
Don't get me started about those stupid light bulbs.
 
subject: Can a servlet listen to something else than http port.. and talk other protocols
 
Similar Threads
Why servlet is better than Applet
Websphere 6.1 host and port
Writing to a text file via URLConnection
How to include Session Time out Tag?
Simple Java Mail : Relaying Denied