Esempio n. 1
0
        private void ReceiveCallback <Tparams>(IAsyncResult ar)
        {
            int bytesRead = client.GetStream().EndRead(ar);
            ActionCallback <Tparams> action = (ActionCallback <Tparams>)ar.AsyncState;

            if (bytesRead > 0)
            {
                returndata += Encoding.ASCII.GetString(buffer, 0, bytesRead);
                buffer      = new byte[BufferSize];
                if (client.Client.Poll(0, SelectMode.SelectRead) || returndata[returndata.Length - 1] != '\n')
                {
                    client.Client.BeginReceive(buffer, 0, BufferSize, SocketFlags.None, new AsyncCallback(ReceiveCallback <Tparams>), action);
                }
                else
                {
                    if (action != null)
                    {
                        action.exec();
                    }
                    receiveStatus = true;
                }
            }
            else
            {
                if (returndata.Length > 1)
                {
                    returndata += Encoding.ASCII.GetString(buffer, 0, bytesRead);
                }
                receiveStatus = true;
            }
        }
Esempio n. 2
0
        public void ConnectCallback <Tparams>(IAsyncResult ar)
        {
            ActionCallback <Tparams> action = (ActionCallback <Tparams>)ar.AsyncState;

            client.EndConnect(ar);
            client.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, 1);
            if (action != null)
            {
                action.exec();
            }
            connectStatus = true;
        }
Esempio n. 3
0
 private void SendCallback <Tparams>(IAsyncResult ar)
 {
     try
     {
         ActionCallback <Tparams> action = (ActionCallback <Tparams>)ar.AsyncState;
         if (action != null)
         {
             action.exec();
         }
         sendStatus = true;
     }
     catch (Exception e)
     {
         Console.WriteLine(e.ToString());
     }
 }