Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2012
    Posts
    6
    Rep Power
    0

    Default TCP ObjectOutput Steam

    Hi I have a little problem with my tcp server client

    Java Code:
    public class Client {
    	private String name = "";
    	private Socket socket = null;
    	private ObjectOutputStream clientOut = null;
    	private ObjectInputStream clientIn = null;
    
    	public Client(Socket socket) throws Exception{
    		this.socket = socket;
                    clientOut = new ObjectOutputStream(this.socket.getOutputStream());
    		clientIn = new ObjectInputStream(this.socket.getInputStream());
    	}
    	
    	public Object ReceiveObject() throws Exception{
    		Object ob = clientIn.readObject();
    		clientIn.reset();
    		return ob;
    	}
    
    	public void SendObjekt(TcpPacket packet) {
    		try {
    			clientOut.writeObject(packet);
    			clientOut.flush();
    			clientOut.reset();
    		} catch (IOException e) {
    
    		}
    
    	}
    }
    thats the client class whitch is generated when a client conencts to the serevr

    And now i dont know why the objectstreams have no function

    or have I to generate a new ObjectIn and Outputstream directly in the send and receive method?

  2. #2
    Nouish is offline Member
    Join Date
    Dec 2012
    Posts
    12
    Rep Power
    0

    Default Re: TCP ObjectOutput Steam

    Make sure to wait for the payload to reach you first.

    Java Code:
    while (condition) {
    
    	if (in.available() < 1) {
    		Thread.sleep(25);
    	}
    
    	// Read data here.
    
    }
    A better implementation would check if the payload is of valid size.

Posting Permissions

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