[xSocket-develop] How to handle this situation in an onData Handler
Status: Inactive
Brought to you by:
grro
|
From: Thomas S. <ts...@ib...> - 2009-05-26 08:25:23
|
Hello,
I'm using xSocket 1.2.1 and I'm really happy how easy it is to use the
Non-Blocking stuff, although I run into the following implementation
problem.
Basically, I have the following onData handler (sorry for the formatting):
public boolean onData(INonBlockingConnection con) throws IOException,
BufferUnderflowException {
EODProtocolContentHandler ch = (EODProtocolContentHandler)
con.getAttachment();
if (ch != null) {
return ch.onData(con);
}
con.resetToReadMark();
con.markReadPosition();
String macAddress =
con.readStringByDelimiter(MCIProtocolConsts.NEWLINE);
String checksum =
con.readStringByDelimiter(MCIProtocolConsts.NEWLINE);
String payLoadLength =
con.readStringByDelimiter(MCIProtocolConsts.NEWLINE);
con.removeReadMark();
// At this point, the header has been read!
// Proceed with reading the payload
ch = new EODProtocolContentHandler(
con.getRemoteAddress().getHostName()
, macAddress
, checksum
, Integer.valueOf(payLoadLength).intValue());
con.setAttachment(ch);
ch.onData(con);
// Proceed with handling the parameter upload
// missing code here ...
return true;
}
This code works fine. It reads a few lines from the socket and then some
kind of payload (compressed XML stream) via a particular content handler.
From the comment "// Proceed with handling the parameter upload on", I
would like to do the following:
1) Writing something back to the client
2) Reading a return code sent by the client
ad 1): works fine by using the con.write method. I'm able to transfer a
few lines and another compressed XML stream to the client.
ad 2): reading the return code although does not work. I'm always
running into the a BufferUnderflowException exception when doing the
following:
con.readStringByDelimiter(MCIProtocolConsts.NEWLINE)
Using the con.markReadPosition ... concepts at this position for reading
the return code from the client doesn't work either, because with the
con.resetToReadMark() at the BEGINNING of the onData handler, it thinks
there should be three lines ...
Any hints are much appreciated!
Thanks,
Thomas
|