Re: [xSocket-develop] xSocket (multiplexed) and serialized objects
Status: Inactive
Brought to you by:
grro
|
From: Jeff C. <JC...@sp...> - 2008-05-29 20:06:38
|
I read and implemented the answer to my first question. ConnectionUtil held the function and usage.
Clientside:
client = new NonBlockingConnection(...);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(bos);
out.writeObject(genericObj);
out.writeObject(DELIMITER);
client.write(bos.size());
client.write(bos.toByteArray());
Server Protocol Handler in onData(...)
int length = ConnectionUtils.validateSufficientDatasizeByIntLengthField(connection);
byte[] test = connection.readBytesByDelimiter(DELIMITER,length);
ByteArrayInputStream bis = new ByteArrayInputStream(test);
ObjectInputStream incomingObjstream = new ObjectInputStream(bis);
Object incomingObj = null;
try{
incomingObj = incomingObjstream.readObject();
}
catch(ClassNotFoundException e){e.printStackTrace();
}
incomingObjstream.close();
2. What is the standard practice to index open connections for sending? I use my protocol handler to read the object, handle the object, throw an event. If the server wants to disconnect or send a message, how do I do a lookup? I could do a singleton HashMap or pass a reference in the event thrown (which doesn't help if it's interacting with another connection) or am I missing something in the xSocket interfaces?
|