|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.javagamesfactory.nioservers.ResponseListener
public class ResponseListener
FIXME: this class has the same bug that originally existed in the StringBasedServer - if it receives fewer than 4 bytes in the first read of a message, it will NOT correctly handle that (it needs the same workaround in SBS, i.e needs to check if the very first read reads fewer than 4 bytes, and if so, ignore it, reset one buffer, advance the other, and try again)
Worker thread that listens to a SocketChannel, receives incoming messages, decodes them, and then passes them on one-by-one as String instances to a specified other class of your choice.
Implements a protocol of:
MSG_LENGTH_IN_BYTES + MESSAGE(there is no explicit delimiting of message start/end)
| Field Summary | |
|---|---|
int |
bufferSize
|
| Constructor Summary | |
|---|---|
ResponseListener(java.lang.String t,
iMessageProcessor mp,
java.nio.channels.SocketChannel sc,
java.nio.charset.Charset charset)
|
|
| Method Summary | |
|---|---|
void |
run()
Continuously reads from the channel, with a blocking-read, until it receives a complete message, which it then passes to the message processor. |
void |
start()
Starts a new thread for this listener |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public int bufferSize
| Constructor Detail |
|---|
public ResponseListener(java.lang.String t,
iMessageProcessor mp,
java.nio.channels.SocketChannel sc,
java.nio.charset.Charset charset)
t - human-readable title of this listener, to make it easier to distinguish between log messages and debuggingmp - processor that will handle any messages that this instance receives and parses into stringssc - the low-level channel to read messages fromcharset - the encoding that the low-level bytes are in so that this instance can decode them into chars| Method Detail |
|---|
public void start()
public void run()
Format of messages is: [length-in-bytes] [message]
length is specified as a 32-bit integer, i.e. 4 bytes
run in interface java.lang.Runnable
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||