Beispiel #1
0
        public static byte[] RemoveByteStuffing(byte[] bytes2Process)
        {
            /*
             * Unescapes characters as defined in 2.2.9
             * Returns True if more data is needed
             */

            List <byte> data = bytes2Process.ToList();
            UECP        uecp = new UECP();

            for (int i = 0; i < data.Count; i++)
            {
                if (data[i] == 0xFD && data[i + 1] == 0x00)
                {
                    data.RemoveAt(i);
                    data[i] = 0xFD;
                }
                if (data[i] == 0xFD && data[i + 1] == 0x01)
                {
                    data.RemoveAt(i);
                    data[i] = 0xFE;
                }
                if (data[i] == 0xFD && data[i + 1] == 0x02)
                {
                    data.RemoveAt(i);
                    data[i] = 0xFF;
                }
            }

            return(data.ToArray());
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            UECP_Parser uecp   = new UECP_Parser();
            UECP        play   = new UECP();
            TcpListener server = new TcpListener(IPAddress.Any, 4002);

            // we set our IP address as server's address, and we also set the port: 9999

            server.Start();                                       // this will start the server

            while (true)                                          //we wait for a connection
            {
                TcpClient client = server.AcceptTcpClient();      //if a connection exists, the server will accept it

                NetworkStream ns = client.GetStream();            //networkstream is used to send/receive messages

                byte[] hello = new byte[100];                     //any message must be serialized (converted to byte array)
                hello = Encoding.Default.GetBytes("hello world"); //conversion string => byte array

                ns.Write(hello, 0, hello.Length);                 //sending the message

                while (client.Connected)                          //while the client is connected, we look for incoming messages
                {
                    byte[] msg = new byte[1024];                  //the messages arrive as byte array
                    //ns.Read(msg, 0, msg.);   //the same networkstream reads the message sent by the client
                    //ns.Read(uecp.UECPFrame, 0, 19);
                    ns.Read(uecp.UECPFrame, 0, uecp.UECPFrame.Length);
                    uecp.ParseFrame(uecp.UECPFrame);
                    //play.Decode();
                    //Console.WriteLine(Encoding.Default.GetString(uecp.UECPFrame).Trim());
                    //Array.Copy(msg, uecp.UECPFrame, 255);
                    //Console.WriteLine("Break Here");
                    //Console.WriteLine(Encoding.Default.GetString(msg).Trim()); //now , we write the message as string
                }
            }
        }