sockets - How to receive an object on a socketServer in java -
i want send object(array) client server. use objectinputstream , objectoutputstream. however, invokes error, these methods not defined in serversocket class. how resolve situation ??`
public int[] readresponse() throws ioexception, classnotfoundexception{ int[] x = new int[5]; objectoutputstream co = new objectoutputstream(serversocket.getoutputstream()); //here error objectinputstream ci = new objectinputstream(serversocket.getinputstream()); // here error co.writeobject(x); x = (int[]) ci.readobject(); (int = 0; < 5; i++){ system.out.println(x[i]); } return x; }
a java.net.serversocket not meant used actual input , output; socket listening on server incoming connection requests accepted, resulting in java.net.socket 1 reading , writing.
socket socket = serversocket.accept(); objectinputstream ci = new objectinputstream(socket.getinputstream());
on client side, java.net.socket created calling constructor , connected, via address, client.
socket socket = new socket( address, port ); objectoutputstream co = new objectoutputstream(socket.getoutputstream());
Comments
Post a Comment