File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Tomcat and the fly likes Socket server inside Tomcat Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Socket server inside Tomcat" Watch "Socket server inside Tomcat" New topic
Author

Socket server inside Tomcat

Marcin Kurek
Greenhorn

Joined: May 11, 2008
Posts: 8
Hi there,

I'm building a system which consists of Flex frontend, Java + Hibernate + MySQL backend and an embedded device, which communicates using standard socket connection.
I'd like to be able to control the hardware from within Flex app.
I think it would be relatively easy if I could set up a socket server inside Tomcat. Is it possible? Even if so, is it considered as a good practice?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61221
    
  66

I cannot see what this has to do with Tomcat in the least.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Marcin Kurek
Greenhorn

Joined: May 11, 2008
Posts: 8
OK, so I'll clarify a bit. Let's assume that user want to send some data to the device.

As for now, I have a standalone java application which talks to hardware on specific port.
Using Flex app, one can make operations on the database as well as talk to device. In the first case, the RemoteObject is used, remote procedure is called, data is retrieved etc. In the second case, Flex app itself opens a socket connection to mentioned java app (yes, it also listens on another port) which in turn, forwards request to device. This is messy and I would like to get rid of that socket connection between Flex and standalone java app.
If I would be able to set up a socket server inside Tomcat, the whole thing would be a lot easier:
1. Device gets connected to the well known port of socket server. For each connecting device server spawns a separate thread.
2. User clicks "fetch client list" in Flex app.
3. Remote procedure is called, which executes socketServer.getClientList() and return result to Flex.

I hope this helps.
Arnold Reuser
Ranch Hand

Joined: Nov 20, 2003
Posts: 196
Hopefully your running at least jdk5 because this version contains Executors which could make your life a bit simpler.
The approach however of spawning application-created threads in Tomcat is not recommended. Read the JSR 154 spec carefully when you would to have more details on this.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16065
    
  21

Actually, since Tomcat is designed as a container for socket-listening services, it would be cleaner architecturally to simply add your own engine to the set Tomcat already has.

However, that seems like a bit of overkill here. Although I may have missed some important details, it sound like maybe a REST service connecting to a backend service provider would be sufficient. JMS and message EJBs are other popular solutions.

Almost any mechanism that can run over HTTP(S) is preferable, since you'll have fewer firewall issues. Although that does come with the restriction that the server can only respond to requests and not send unsolicited network traffic back to clients.


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

Joined: May 11, 2008
Posts: 8
Thank you for your responses! I guess I need to make some research
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Socket server inside Tomcat