Open socket connection on a servlet container
I've written a very simple server that accepts socket connections on a specific port and communicates with clients over that socket. Now I have a client lib which works perfectly fine in J2SE apps.
However, if I try to use that lib in a Servlet (the Servlet being the client) to communicate with the server it doesn't work. Unfortunately there is no Exception or something that could help me. Instead when using the lib simply nothing happens. That is the call to the method within which the socket is opened just blocks indefinitely while no connection is made to the server.
I reckon this 开发者_运维知识库could be a general problem. Maybe things like that are not allowed from within a Servlet? But even if not I would at least expect that some Exception to be thrown.
The Servlet Container is Tomcat by the way.
Has anyone got an idea as to why this doesn't work?
Ok here is there actual problem:
It seems to be a difference in behaviour between Windows and Linux. I developed the server + lib under Linux while Tomcat runs on a Windows machine.
Among other things the server I told you about executes a command via ProcessBuilder. What actually blocked indefinitely was the Process#waitFor.
That is under Windows. Under Linux it works just fine and returns as soon as the process is finished. Under Windows however Process#waitFor only returns when I read the Process's InputStream for some reason.
Sorry!
精彩评论