Example #1
0
    public QTResponsableMessage(QTResponsableMessage sourceMessage = null)
    {
        onResponse += debugResponse;

        if (sourceMessage != null)
        {
            responseID = sourceMessage.responseID;
        }
        else
        {
            responseID = Guid.NewGuid().ToString();
        }
    }
Example #2
0
    public void sendMessage(QTMessage message)
    {
        lock (sendLock) {
            try {
                if (client.Connected == false)
                {
                    return;
                }

                byte[] bytes     = QTUtils.MessageToByteArray(message);
                byte[] sizeBytes = BitConverter.GetBytes(bytes.Length);

                try {
                    debugSent(sizeBytes, bytes);

                    thread.stream.Write(sizeBytes, 0, sizeBytes.Length);
                    thread.stream.Write(bytes, 0, bytes.Length);
                } catch (Exception e) {
                    QTDebugger.instance.debugWarning(QTDebugger.debugType.NETWORK, "[" + type + "_base] Error while writing the NetworkStream-");
                    QTDebugger.instance.debugError(QTDebugger.debugType.NETWORK, e);

                    closeConnection();
                }

                var responsableValid = message as QTResponsableMessage;
                if (responsableValid != null)
                {
                    QTResponsableMessage responseMessage = (QTResponsableMessage)message;
                    awaitingResponse.Add(responseMessage.responseID, responseMessage);
                }

                onMessageSent(message);
            } catch (Exception e) {
                Debug.LogWarning(e);
            }
        }
    }
Example #3
0
    public void processQueue()
    {
        lock (recieveLock) {
            try {
                if (queuedMessages.Count < 1)
                {
                    return;
                }

                List <QTMessage> queue = queuedMessages.ToList();
                foreach (QTMessage message in queue)
                {
                    try {
                        onMessageRecieved(message);

                        var responsableValid = message as QTResponsableMessage;
                        if (responsableValid != null)
                        {
                            QTResponsableMessage responseMessage = (QTResponsableMessage)message;
                            if (awaitingResponse.ContainsKey(responseMessage.responseID))
                            {
                                awaitingResponse[responseMessage.responseID].onResponse(responseMessage);
                                awaitingResponse.Remove(responseMessage.responseID);
                            }
                        }
                    } catch (Exception e) {
                        Debug.LogError(e);
                    }

                    queuedMessages.Remove(message);
                }
            } catch (Exception e) {
                Debug.LogWarning(e);
            }
        }
    }
Example #4
0
 public LoginReplyMessage(QTResponsableMessage _message = null) : base(_message)
 {
     messageType = type.LOGIN_REPLY;
 }
Example #5
0
 public RoomsMessage(QTResponsableMessage _message = null) : base(_message)
 {
     messageType = type.ROOMS;
 }
Example #6
0
 public InstanceMessage(QTResponsableMessage _message = null) : base(_message)
 {
     messageType = type.INSTANCE;
 }
Example #7
0
 public RegisterReplyMessage(QTResponsableMessage _message = null) : base(_message)
 {
     messageType = type.REGISTER_REPLY;
 }
Example #8
0
 public void debugResponse(QTResponsableMessage message)
 {
     QTDebugger.instance.debug(QTDebugger.debugType.NETWORK, "Got response for message with ID - " + message.responseID);
 }
Example #9
0
 public HeartbeatMessage(QTResponsableMessage _message = null) : base(_message)
 {
     messageType = type.HEARTBEAT;
 }