Exemplo n.º 1
0
        public void UdpUnreliableMessageSendTest()
        {
            byte[] TestData = new byte[] { 1, 2, 3, 4, 5, 6 };
            using (UdpConnectionListener listener = new UdpConnectionListener(new IPEndPoint(IPAddress.Any, 4296)))
                using (UdpConnection connection = new UdpClientConnection(new IPEndPoint(IPAddress.Loopback, 4296)))
                {
                    MessageReader output = null;
                    listener.NewConnection += delegate(NewConnectionEventArgs e)
                    {
                        e.Connection.DataReceived += delegate(DataReceivedEventArgs evt)
                        {
                            output = evt.Message;
                        };
                    };

                    listener.Start();
                    connection.Connect();

                    for (int i = 0; i < 4; ++i)
                    {
                        var msg = MessageWriter.Get(SendOption.None);
                        msg.Write(TestData);
                        connection.Send(msg);
                        msg.Recycle();
                    }

                    Thread.Sleep(10);
                    for (int i = 0; i < TestData.Length; ++i)
                    {
                        Assert.AreEqual(TestData[i], output.ReadByte());
                    }
                }
        }
    public void SendToServer(byte[] data)
    {
        UdpClientConnection udpClientConnection = udpConnection as UdpClientConnection;

        if (udpClientConnection != null)
        {
            udpClientConnection.Send(data);
        }
    }
Exemplo n.º 3
0
        /**
         * Helper method that fetches a new Reliable message writer for the specified connection,
         * invokes the specified write method, then sends the resulting message to the server.
         * Any errors during message sending will be ignored.
         */
        public static void SendReliableMessage(this UdpClientConnection connection, Action <MessageWriter> write)
        {
            var writer = MessageWriter.Get(SendOption.Reliable);

            try
            {
                write(writer);
                connection.Send(writer);
            } catch { /* Ignored */ Console.Out.WriteLine("Oops"); }
            writer.Recycle();
        }
Exemplo n.º 4
0
        public void SendMovement(ushort xpos, ushort ypos, ushort xvel, ushort yvel)
        {
            MessageWriter writer = MessageWriter.Get(SendOption.None);

            writer.StartMessage((byte)MMTags.GameData);
            writer.Write(_lobbyCode);
            writer.Write((ushort)5);
            writer.Write((byte)GameDataTags.Data);
            writer.WritePacked(_clientId);
            writer.Write(xpos);
            writer.Write(ypos);
            writer.Write(xvel);
            writer.Write(yvel);

            _connection.Send(writer);
        }