- Joined
- May 7, 2010
- Messages
- 1
- Reaction score
- 0
Non-Blocking Object Serialization via a socket
Client side:
Socket server = Socket(serverAddress, serverPort).connect();
OutputStream outStream = server.getOutputStream();
OutputObjectStream objectOutStream = new OutputObjectStream(outStream);
//write to server
outStream.write(1);
outObjectStream.write(MySerializableObject);
ServerSide:
Socket client = serverSocket.accept();
InputStream inStream = client.getInputStream();
InputObjectStream inObjectStream = new InputObjectStream(inStream);
//main driving while loop of the server
while (running_forever) {
//do all kinds of work
if (inStream.available() >0) { //NON-BLOCKING
//read in the number the client sent (pick it off the stream)
inStream.read();
//read in the object the client sent
Object = inObjectStream.readObject();
}
//do other kinds of work
}
Client side:
Socket server = Socket(serverAddress, serverPort).connect();
OutputStream outStream = server.getOutputStream();
OutputObjectStream objectOutStream = new OutputObjectStream(outStream);
//write to server
outStream.write(1);
outObjectStream.write(MySerializableObject);
ServerSide:
Socket client = serverSocket.accept();
InputStream inStream = client.getInputStream();
InputObjectStream inObjectStream = new InputObjectStream(inStream);
//main driving while loop of the server
while (running_forever) {
//do all kinds of work
if (inStream.available() >0) { //NON-BLOCKING
//read in the number the client sent (pick it off the stream)
inStream.read();
//read in the object the client sent
Object = inObjectStream.readObject();
}
//do other kinds of work
}