Hi:
I am trying to develop a client socket connection inside an EJB (I have some reasons for using sockets instead of a clean java solution).
Shown below, is the simple code I am using to connect to a socket server. The code is tested outside EJB framework and works fine.
But when I use it inside EJB framework, the connection to the socket server is made by the EJB [m_clientSocket = new Socket(address, port);] without any problem.
But when I write something to the stream, nothing is sent to the socket server, until the stream or the client socket is closed. This is a problem because I am unable to read the reply from the socket server, since the socket needs to be closed for the data to the flushed to the server.
1. I tried fushing the stream without any result.
2. When I close the output stream, the client socket itself is being closed.
Anybody successfully worked on a socket client inside an EJB, please help.
Thanks,
JKN
..................
Socket m_clientSocket;
DataOutputStream m_outToServer;
BufferedReader m_inFromServer;
....................
m_clientSocket = new Socket(address, port);
m_outToServer = new DataOutputStream(m_clientSocket.getOutputStream());
m_inFromServer = new BufferedReader(new InputStreamReader(m_clientSocket.getInputStream()));
m_outToServer.writeBytes("Message to Socket server");
m_outToServer.flush();
//m_outToServer.close();
m_inFromServer = new BufferedReader(new InputStreamReader(m_clientSocket.getInputStream()));
String reply = this.m_inFromServer.readLine();
-
Socket client connection from EJB (4 messages)
- Posted by: jkn jkn
- Posted on: November 21 2001 12:19 EST
Threaded Messages (4)
- Socket client connection from EJB by Pranab Ghosh on November 21 2001 15:45 EST
- Socket client connection from EJB by a a on November 30 2001 10:41 EST
- Socket client connection from EJB by a a on November 30 2001 10:52 EST
- Socket client connection from EJB by a a on November 30 2001 10:41 EST
- documentation by jp jp on May 29 2009 11:23 EDT
-
Socket client connection from EJB[ Go to top ]
- Posted by: Pranab Ghosh
- Posted on: November 21 2001 15:45 EST
- in response to jkn jkn
I also had a bad experience trying to make socket connection from an ejb. In my case, I was trying to make a SOAP call. The call simply hung the whole container.
It's probably not a good idea to make this kind of system calls from inside the ejb container. I switched to making the call from the servlet engine and everything works fine.
Pranab -
Socket client connection from EJB[ Go to top ]
- Posted by: a a
- Posted on: November 30 2001 10:41 EST
- in response to Pranab Ghosh
EJB spec clearly says sockets should not be used in EJB's.
I wonder why EJB compilers does not flash an error when developer makes mistake of using sockets. -
Socket client connection from EJB[ Go to top ]
- Posted by: a a
- Posted on: November 30 2001 10:52 EST
- in response to a a
Hi,
Sorry about the wrong information. EJB spec says that enterprise bean must not attempt to listen on a socket.
But it can open a socket and use it just like JDBC.
Sockets has to be closed when the ejb is passivated. Socket connection has to be established when the ejb is activated. -
documentation[ Go to top ]
- Posted by: jp jp
- Posted on: May 29 2009 11:23 EDT
- in response to jkn jkn
do you known where I can find info about EJB sockets ? I want to my clients connect to me by EJB-socket ... may that not possible.