Search in sources :

Example 6 with SOCMessage

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);
    }
}
Also used : SOCMessage(soc.message.SOCMessage) ConnectException(java.net.ConnectException) EOFException(java.io.EOFException)

Aggregations

SOCMessage (soc.message.SOCMessage)6 SOCDevCardAction (soc.message.SOCDevCardAction)3 SOCDiscardRequest (soc.message.SOCDiscardRequest)2 SOCPlayerElement (soc.message.SOCPlayerElement)2 SOCSimpleRequest (soc.message.SOCSimpleRequest)2 Connection (soc.server.genericServer.Connection)2 EOFException (java.io.EOFException)1 IOException (java.io.IOException)1 ConnectException (java.net.ConnectException)1 Vector (java.util.Vector)1 SOCBoardLarge (soc.game.SOCBoardLarge)1 SOCInventoryItem (soc.game.SOCInventoryItem)1 SOCResourceSet (soc.game.SOCResourceSet)1 SOCShip (soc.game.SOCShip)1 SOCAcceptOffer (soc.message.SOCAcceptOffer)1 SOCChangeFace (soc.message.SOCChangeFace)1 SOCChoosePlayerRequest (soc.message.SOCChoosePlayerRequest)1 SOCClearOffer (soc.message.SOCClearOffer)1 SOCFirstPlayer (soc.message.SOCFirstPlayer)1 SOCGameElements (soc.message.SOCGameElements)1