Socket client connection from EJB

Discussions

EJB programming & troubleshooting: Socket client connection from EJB

  1. Socket client connection from EJB (4 messages)

    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();

    Threaded Messages (4)

  2. Socket client connection from EJB[ Go to top ]

    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
  3. Socket client connection from EJB[ Go to top ]

    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.
  4. Socket client connection from EJB[ Go to top ]

    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.
  5. documentation[ Go to top ]

    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.