コード例 #1
0
        public async void BeginReadData()
        {
            try
            {
                int bytesread = await _stream.ReadAsync(_buffer, 0, BUFFERSIZE);

                while (bytesread > 0)
                {
                    int offset = 0;
                    do
                    {
                        var packet = _decoder.GetFromBytes(_buffer, ref offset);
                        if (packet != null)
                        {
                            PacketReceived?.Invoke(packet);
                        }
                        else if (offset < bytesread)
                        {
                            _dataoffset = bytesread - offset;
                            Array.Copy(_buffer, offset, _buffer, 0, _dataoffset);
                            break;
                        }
                    } while (offset < bytesread);
                    bytesread = await _stream.ReadAsync(_buffer, _dataoffset, BUFFERSIZE - _dataoffset);
                }
            }
            catch
            {
                Console.WriteLine("Client Read Aborted");
            }
            Console.WriteLine("DONE");
        }
コード例 #2
0
ファイル: TestClass.cs プロジェクト: Corey255A1/WunderNet2
        public static bool TestWunderLayer(string xmlpath)
        {
            var          layerTest = new WunderLayer(xmlpath);
            WunderPacket w         = layerTest.GetNewPacket("Message");

            w.Set("MessageData", "This is a test");
            byte[] test = w.GetBytes();
            Console.WriteLine(test.Length);
            WunderPacket o = layerTest.GetNewPacket("ObjectInfo");

            o.Set("VX", 3.4);
            Console.WriteLine(w.ToString());
            Console.WriteLine(o.ToString());
            int          offset = 0;
            WunderPacket decode = layerTest.GetFromBytes(test, ref offset);

            Console.WriteLine("Decoded Data: " + decode.Get("MessageData"));
            test   = o.GetBytes();
            offset = 0;
            decode = layerTest.GetFromBytes(test, ref offset);
            Console.WriteLine("Decoded Data: " + decode.Get("VX"));
            return(true);
        }