Example #1
0
            public void Send(byte[] bytes)
            {
                if (Configuration.Network.UdpProtocol == UdpProtocol.COBS)
                {
                    byte[] rawBytes = COBSEncoding.Encode(bytes);
                    byte[] msg      = new byte[rawBytes.Length + 1];

                    Array.Copy(rawBytes, 0, msg, 0, rawBytes.Length);
                    msg[rawBytes.Length] = 0;

                    IPEndPoint endPoint = new IPEndPoint(IPAddress.Broadcast, Configuration.Network.UdpPort);
                    m_client.Send(msg, msg.Length, endPoint);
                }
                else if (Configuration.Network.UdpProtocol == UdpProtocol.Plain)
                {
                    byte[] controlSequence = new byte[] { 255, 255, 255, 255 };
                    byte[] payloadLength   = BitConverter.GetBytes((ushort)bytes.Length);

                    byte[] msg = new byte[4 + 2 + bytes.Length];

                    Array.Copy(controlSequence, 0, msg, 0, controlSequence.Length);
                    Array.Copy(payloadLength, 0, msg, 4, payloadLength.Length);
                    Array.Copy(bytes, 0, msg, 4 + 2, bytes.Length);

                    IPEndPoint endPoint = new IPEndPoint(IPAddress.Broadcast, Configuration.Network.UdpPort);
                    m_client.Send(msg, msg.Length, endPoint);
                }
            }
Example #2
0
            public void Send(List <byte[]> bytes)
            {
                List <byte> final = new List <byte>();

                foreach (byte[] packet in bytes)
                {
                    byte[] rawBytes    = COBSEncoding.Encode(packet);
                    byte[] finalPacket = new byte[rawBytes.Length + 1];

                    Array.Copy(rawBytes, 0, finalPacket, 0, rawBytes.Length);
                    finalPacket[rawBytes.Length] = 0;

                    final.AddRange(finalPacket);
                }

                byte[] msg = final.ToArray();

                IPEndPoint endPoint = new IPEndPoint(IPAddress.Broadcast, Configuration.Network.UdpPort);

                m_client.Send(msg, msg.Length, endPoint);
            }