Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to serve a socket from a Java EE application?

We would like to serve some client requests within our Java EE application server (JBoss 4.2.3). I read that the Java EE spec doesn't allow opening a socket from an enterprise bean. But the spec suggests no alternatives.

Specifically, enterprise beans should not:

  • listen on, accept connections on, or multicast from a network socket

So the question is: What can I do to serve some binary tcp based protocols (not http) from within an application server?

Here someone suggests to implement a resource adapter. Is this the way you have to go or are there other (easier) solutions?

like image 568
tangens Avatar asked Jan 14 '10 10:01

tangens


People also ask

How does a server socket work in java?

ServerSocket is a java.net class that provides a system-independent implementation of the server side of a client/server socket connection. The constructor for ServerSocket throws an exception if it can't listen on the specified port (for example, the port is already being used).


1 Answers

You're right, since you can declare transactions for every thing in Java EE they must be supported from all components you want to connect. Files if any should be stored in a database. Everything should be controlled by the container, because it the only way to have a scaling application using Java EE.

A few options:

  • Implement a Connector (JCA) a example is here: http://www.theserverside.com/tt/articles/article.tss?l=J2EE1_4 probably the best way if you have existing clients.

  • Use Java Message Queues

  • The relationship between this techniques is discussed here http://java.sun.com/products/jms/faq.html#relship_ejbs

  • Write server who stores requests in the database.(No Tx support)

  • If you have only one server and it seems too much overhead, you could ignore these aspects and follow Vinegars suggestion. But if you need Tx later or additional nodes this part has to be redesigned.

like image 113
stacker Avatar answered Sep 28 '22 19:09

stacker