This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Hello - I need my EJB to communicate via sockets with a java application. Can this be done? Can I place the code for a client socket somewhere in the Bean (in a method?) and have the server code establish a connection and listen for requests from client on the java application? Thanks for the help! BRH
No, this is against the EJB spec. There are several things you can do - a popular one is to use a JMS queue, have the bean act as the producer to the queue and another non-EJB class be the consumer. The bean can send a message to the queue and the consumer can open the socket and write the message to it.
Hi, But this takes out the charm of the request-response type of behavior available in the Socket Communications. JMS is typically asynchronous and if the reply is expected back by the EJB from the socket server synchronously, JMS will have all round abouts of creating a temp queue, block on it and stuff like that which is not at all desirable for a 24X7 type of applications. Please refer point 5 of section EJB RESTRICTIONS of this link: http://www.javaworld.com/javaworld/jw-08-2000/jw-0825-ejbrestrict.html it sayeth, EJBs CAN open Client socket for communication. I have personally used URLConnection object to extract dynamic content like currency rate, weather info etc., from within a Stateless Session Bean. I am not sure if it works for pure Sockets. Ultimately, URLConnection must boil down to a Socket under the covers right? Anybody who had successfully implemented a client socket from within EJBs, please share your experience. Please.... This is a major concern when we have External Socket Server is available as a product and we have no way to reengineer or add a layer of JMS as suggested. Socket client is just another resource connector to an external world. But this topic is always being seen as BIG NO NO..... in EJB Context :-) Rgds Muthu