コード例 #1
0
ファイル: MyClient.cs プロジェクト: Danielg686/DataDriven
        void ReadInData()
        {
            NetworkMessage sm = new NetworkMessage();

            NetIncomingMessage im;

            while ((im = client.ReadMessage()) != null)
            {
                switch (im.MessageType)
                {
                case NetIncomingMessageType.Data:
                    byte[] msg = im.ReadBytes(im.LengthBytes);
                    sm = NetworkMessage.Deserialize(msg);

                    OutputQueue.AddToQueue(sm.GetData());

                    break;

                case NetIncomingMessageType.DiscoveryResponse:
                    Debug.WriteLine("Found server at " + im.SenderEndPoint + " name: " + im.ReadString());
                    client.Connect(im.SenderEndPoint);
                    break;

                case NetIncomingMessageType.UnconnectedData:
                    Debug.WriteLine("Received from " + im.SenderEndPoint + ": " + im.ReadString() + Environment.NewLine);
                    break;
                }
                client.Recycle(im);
            }
        }
コード例 #2
0
        void ReadInData()
        {
            NetworkMessage client_input = new NetworkMessage();

            NetIncomingMessage im;

            while ((im = server.ReadMessage()) != null)
            {
                switch (im.MessageType)
                {
                case NetIncomingMessageType.Data:
                    byte[] msg = im.ReadBytes(im.LengthBytes);
                    client_input = NetworkMessage.Deserialize(msg);

                    OutputQueue.AddToQueue(client_input.GetData());

                    Debug.WriteLine(msg);
                    break;

                case NetIncomingMessageType.DiscoveryRequest:
                    // Create a response
                    NetOutgoingMessage om = server.CreateMessage();
                    om.Write("Connecting to DOG server");
                    server.SendDiscoveryResponse(om, im.SenderEndPoint);
                    break;

                case NetIncomingMessageType.UnconnectedData:
                    Debug.WriteLine("Received from " + im.SenderEndPoint + ": " + im.ReadString() + Environment.NewLine);
                    break;
                }
                server.Recycle(im);
            }
        }
コード例 #3
0
ファイル: InputQueue.cs プロジェクト: Danielg686/DataDriven
        public static void Process()
        {
            while (instance.inputQueue.Count > 0)
            {
                DataMessage msg = instance.inputQueue.Dequeue();

                if (msg.sendType == SEND_TYPE.LOCAL)
                {
                    OutputQueue.AddToQueue(msg);
                }
                else
                {
                    MyClient.Instance.SendMessageToServer(msg);
                }
            }
        }