Exemple #1
0
    private void UpdateMessagePump()
    {
        if (!IsOnline)
        {
            return;
        }

        int recHostId, cnnId, channelId;

        byte[] dataBuffer = new byte[MSG_BYTE_SIZE];
        int    dataSize;

        NetworkEventType networkEventType =
            NetworkTransport.Receive(out recHostId, out cnnId, out channelId,
                                     dataBuffer, dataBuffer.Length, out dataSize, out _error);

        switch (networkEventType)
        {
        case NetworkEventType.Nothing:
            break;

        case NetworkEventType.ConnectEvent:
            OnConnect(cnnId, channelId, recHostId, _error);
            break;

        case NetworkEventType.DisconnectEvent:
            Debug.Log(string.Format("Disconnected from game server", cnnId));
            IsOnline = false;
            OnDisconnectedEvent.Raise();
            break;

        case NetworkEventType.DataEvent:
            NetMsg netMsg = MsgSerializer.DeserializeNetMsg(dataBuffer);
            OnData(cnnId, channelId, recHostId, netMsg);
            break;

        case NetworkEventType.BroadcastEvent:
            Debug.Log("Unexpected Network Event");
            break;
        }
    }