예제 #1
0
 protected virtual void OnClientDisconnected(object sender, Socket_EventArgs e)
 {
     if (ClientDisconnected != null)
     {
         ClientDisconnected(sender, e);
     }
 }
예제 #2
0
 protected virtual void OnDataReceived(object sender, Socket_EventArgs e)
 {
     if (DataReceived != null)
     {
         DataReceived(sender, e);
     }
 }
예제 #3
0
        private async Task Read()
        {
            while (shouldRead)
            {
                if (sock.Connected && sock.GetStream().CanRead)
                {
                    List <byte[]> byteList = new List <byte[]>();

                    while (sock.GetStream().DataAvailable)
                    {
                        byte[] buffer = new byte[1024];
                        int    read   = await sock.GetStream().ReadAsync(buffer, 0, buffer.Length);

                        byteList.Add(buffer);
                    }

                    if (byteList.Count > 0)
                    {
                        byte[] data = byteList.SelectMany(x => x).ToArray();

                        Socket_EventArgs args = new Socket_EventArgs(this);
                        args.Data = new Socket_Data(data);

                        OnDataReceived(this, args);
                        byteList.Clear();
                    }
                }

                await Task.Delay(1000);
            }
        }
예제 #4
0
        public void Send(byte[] buffer)
        {
            if (sock.Connected && sock.GetStream().CanWrite)
            {
                sock.GetStream().Write(buffer, 0, buffer.Length);
                sock.GetStream().Flush();

                Socket_EventArgs args = new Socket_EventArgs(this);
                args.Data = new Socket_Data(buffer);

                OnDataSent(this, args);
            }
            else
            {
                if (QueueData)
                {
                }
                else
                {
                    //throw new Exception("Socket stream not available for writing");
                }
            }
        }
예제 #5
0
 protected virtual void OnDataReceived(object sender, Socket_EventArgs e)
 {
     DataReceived?.Invoke(sender, e);
 }
예제 #6
0
 protected virtual void OnDataSent(object sender, Socket_EventArgs e)
 {
     DataSent?.Invoke(sender, e);
 }
예제 #7
0
 protected virtual void OnDisconnected(object sender, Socket_EventArgs e)
 {
     Disconnected?.Invoke(sender, e);
 }