Ejemplo n.º 1
0
        public void UDPLoop()
        {
            Packet lastPacket;
            int    lastavail;

            while (connected)
            {
                //Receive
                if ((lastavail = udp.Available) > 0)
                {
                    lastPacket      = new Packet();
                    lastPacket.data = new byte[lastavail];
                    udp.Receive(lastPacket.data);
                    OnReceive(lastPacket.data);
                }

                if (cidinit)
                {
                    //Send
                    while (UDPout.Count > 0)
                    {
                        if (UDPout.TryDequeue(out lastPacket))
                        {
                            udp.SendBufferSize = lastPacket.data.Length;
                            udp.SendTo(lastPacket.data, serverUDPep);
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        //Mostly useless since commands are important however the UDPINIT command relies on sending a datagram to expose remote endpoint to the server
        public void SendCommandUDP(string cmd)
        {
            cmdtosend.command = cmd;
            Packet pts = new Packet();

            pts.data = PacketUtils.Pack(cmdtosend.EncodeRaw(), PacketUtils.GenerateHeader(cid, NetData.TYPE_CMD, 0, cmdtosend.GetLength()));
            UDPout.Enqueue(pts);
        }
Ejemplo n.º 3
0
        public void SendTransform(Transform t, byte id)
        {
            ttosend          = new NetTransform();
            ttosend.position = t.localPosition;
            ttosend.rotation = t.localRotation.eulerAngles;
            ttosend.scale    = t.localScale;
            Packet pts = new Packet();

            pts.data = PacketUtils.Pack(ttosend.EncodeRaw(), PacketUtils.GenerateHeader(cid, NetData.TYPE_NETTRANSFORM, id, ttosend.GetLength()));
            UDPout.Enqueue(pts);
        }