Пример #1
0
 private void OnReceivedData(byte[] data)
 {
     ActionDone(RegisterCallbackType.ReceivedData, data);
     Array.Clear(data, 0, 10000);
     client.GetStream().BeginRead(data, 0, 10000, (asyncResult) =>
     {
         BaseTCPSocket baseSock = (BaseTCPSocket)asyncResult.AsyncState;
         baseSock.OnReceivedData(data);
     }, this);
 }
Пример #2
0
        public override void Connect(IPEndPoint ep)
        {
            client.BeginConnect(ep.Address, ep.Port, (ar) => {
                BaseTCPSocket sock = (BaseTCPSocket)ar.AsyncState;
                sock.client.EndConnect(ar);

                if (sock.client.Connected)
                {
                    var data = new byte[10000];
                    sock.client.GetStream().BeginRead(data, 0, 10000, (asyncResult) =>
                    {
                        BaseTCPSocket baseSock = (BaseTCPSocket)asyncResult.AsyncState;
                        baseSock.OnReceivedData(data);
                    }, sock);
                }
                sock.ActionDone(RegisterCallbackType.ConnectDone, sock.client.Connected);
            }, this);
        }