use of soc.message.SOCMessage in project JSettlers2 by jdmonin.
the class StringConnection method run.
/**
* For server-side; continuously read and treat input.
* You must create and start the thread.
* We are on server side if ourServer != null.
*<P>
* When starting the thread, {@link #getData()} must be null.
*/
public void run() {
Thread.currentThread().setName("connection-srv-localstring");
if (ourServer == null)
return;
ourServer.addConnection(this);
try {
final InboundMessageQueue inQueue = ourServer.inQueue;
if (!in_reachedEOF) {
String firstMsg = readNext();
// parse
final SOCMessage msgObj = SOCMessage.toMsg(firstMsg);
if (!ourServer.processFirstCommand(msgObj, this)) {
if (msgObj != null)
inQueue.push(msgObj, this);
}
}
while (!in_reachedEOF) {
// blocks until next message is available
final String msgStr = readNext();
final SOCMessage msgObj = SOCMessage.toMsg(msgStr);
if (msgObj != null)
inQueue.push(msgObj, this);
}
} catch (Exception e) {
D.ebugPrintln("Exception in StringConnection.run - " + e);
if (D.ebugOn) {
e.printStackTrace(System.out);
}
if (in_reachedEOF) {
return;
}
error = e;
ourServer.removeConnection(this, false);
}
}
Aggregations