Results 1 to 5 of 5
- 01-08-2009, 02:00 PM #1
Member
- Join Date
- Jan 2009
- Location
- Delft
- Posts
- 9
- Rep Power
- 0
Stops when opening ObjectInputStream
Hello,
My server stops after a client is connected, a socket is opened and when its about to open a ObjectInputStream. I checked it with short messages to the console that it just stalls before doing that. Here is the bit of code that it stops:Java Code:public void listen(){ try{ server = new ServerSocket(4321); System.out.println(server.getInetAddress()); } catch(IOException e){ System.out.println(e); } while(true){ listensocket(); } } public void listensocket(){ //Server accepts client try{ clientsocket = server.accept(); } catch(IOException e){ System.out.println("Port not accepter: 4321"); System.exit(-1); } //Server begins to receive and gets ready to send try{ //the program stops here input = new ObjectInputStream(clientsocket.getInputStream()); output = new ObjectOutputStream(clientsocket.getOutputStream()); }
- 01-08-2009, 03:40 PM #2
Senior Member
- Join Date
- Nov 2008
- Posts
- 286
- Rep Power
- 5
Silly question, but are you actually [i]sending[i] anythiing to the server from the client?
When you create an ObjectInputStream, the constructor will not return until it has read the object header stream. So over a network, if you have an ObjectInputStream at one end sitting waiting for the header, but no corresponding ObjectOutputStream ever actually sends it that header from the other end of the connection, then your server will hang (or rather, the listening thread will hang) until the socket times out.Neil Coffey
Javamex - Java tutorials and performance info
- 01-08-2009, 03:55 PM #3
Member
- Join Date
- Jan 2009
- Location
- Delft
- Posts
- 9
- Rep Power
- 0
A totally legitimate question. Here is the code the client uses to send to the server:
I hope this helps to clarify the problem and I would like to thank you for your time.Java Code:public Object send(Object aanroep){ Object antwoord = null; try { socket = new Socket(SERVER, POORT); input = new ObjectInputStream(socket.getInputStream()); output = new ObjectOutputStream(socket.getOutputStream()); output.writeObject(aanroep); antwoord = input.readObject(); socket.close(); }
- 01-08-2009, 04:00 PM #4
Senior Member
- Join Date
- Nov 2008
- Posts
- 286
- Rep Power
- 5
OK, what you've got is a kind of "remote deadlock". The ObjectInputStream on the client is waiting for the object stream from the server before proceeding, but the server isn't going to send that, because its ObjectInputStream is waiting for the header from the client before proceeding...
Neil Coffey
Javamex - Java tutorials and performance info
- 01-09-2009, 04:19 PM #5
Member
- Join Date
- Jan 2009
- Location
- Delft
- Posts
- 9
- Rep Power
- 0
Similar Threads
-
opening project in eclipse
By keioGirl in forum EclipseReplies: 1Last Post: 04-23-2009, 03:09 PM -
opening of an exe in JFrame
By smartsubroto in forum New To JavaReplies: 3Last Post: 07-16-2008, 05:01 AM -
Opening a workspace twice
By javaplus in forum EclipseReplies: 0Last Post: 01-08-2008, 09:56 AM -
Bouncing Ball Just Suddenly Stops Mid Bounce
By adlb1300 in forum Java 2DReplies: 1Last Post: 12-03-2007, 02:58 PM -
Opening URLConnection
By Java Tip in forum Java TipReplies: 0Last Post: 11-24-2007, 07:37 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks