Results 1 to 5 of 5
  1. #1
    Norberhuis is offline Member
    Join Date
    Jan 2009
    Location
    Delft
    Posts
    13
    Rep Power
    0

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

  2. #2
    neilcoffey is offline Senior Member
    Join Date
    Nov 2008
    Posts
    286
    Rep Power
    7

    Default

    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.

  3. #3
    Norberhuis is offline Member
    Join Date
    Jan 2009
    Location
    Delft
    Posts
    13
    Rep Power
    0

    Default

    A totally legitimate question. Here is the code the client uses to send to the server:
    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();
    		}
    I hope this helps to clarify the problem and I would like to thank you for your time.

  4. #4
    neilcoffey is offline Senior Member
    Join Date
    Nov 2008
    Posts
    286
    Rep Power
    7

    Default

    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...

  5. #5
    Norberhuis is offline Member
    Join Date
    Jan 2009
    Location
    Delft
    Posts
    13
    Rep Power
    0

    Default

    Thank you very much. I got it fixed by swapping the streams and making sure the object is first send.

Similar Threads

  1. opening project in eclipse
    By keioGirl in forum Eclipse
    Replies: 1
    Last Post: 04-23-2009, 04:09 PM
  2. opening of an exe in JFrame
    By smartsubroto in forum New To Java
    Replies: 3
    Last Post: 07-16-2008, 06:01 AM
  3. Opening a workspace twice
    By javaplus in forum Eclipse
    Replies: 0
    Last Post: 01-08-2008, 10:56 AM
  4. Bouncing Ball Just Suddenly Stops Mid Bounce
    By adlb1300 in forum Java 2D
    Replies: 1
    Last Post: 12-03-2007, 03:58 PM
  5. Opening URLConnection
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-24-2007, 08:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •