Exemplo n.º 1
0
 public void Send(IPEndPoint sendTo, byte[] data, int type = 0)
 {
     try
     {
         byte[] payload = new XyzMessageBuilder().Add(XyzUtils.Deflate(data), type).ToArray();
         this.client.BeginSend(payload, payload.Length, sendTo, null, this.client);
     }
     catch (Exception)
     {
     }
 }
Exemplo n.º 2
0
        private void DataReceived(IAsyncResult ar)
        {
            IPEndPoint endpoint = null;

            byte[]       bytes    = client.EndReceive(ar, ref endpoint);
            XyzMessage[] messages = new XyzMessageDecoder(bytes).Decode();

            client.BeginReceive(DataReceived, client);

            on_Message?.Invoke(endpoint, XyzUtils.Inflate(messages[0].Bytes), messages[0].Type);
        }
Exemplo n.º 3
0
 public async void Send(byte[] data, int type = 0)
 {
     try
     {
         byte[] payload = new XyzMessageBuilder().Add(XyzUtils.Deflate(data), type).ToArray();
         await this.stream.WriteAsync(payload, 0, payload.Length);
     }
     catch (Exception)
     {
     }
 }
Exemplo n.º 4
0
        public async Task Receiver()
        {
            try
            {
                byte[] header = await ReadBytes(5);

                int length = BitConverter.ToInt32(header, 0);
                int type   = header[4];

                byte[] message_bytes = await ReadBytes(length);

                this.OnMessage?.Invoke(XyzUtils.Inflate(message_bytes), type);
            }
            catch (Exception)
            {
                Disconnect(true);
            }

            if (client.Connected && !disconnected)
            {
                await Receiver();
            }
        }