Пример #1
0
 private void ConnectCallBack(IAsyncResult ar)
 {
     socket = (Socket)ar.AsyncState;
     session = new Session(socket, bufferSize);
     if (session.IsConnected)
     {
         timer.Start();
         Console.WriteLine("Connected to server at {0}", socket.RemoteEndPoint.ToString());
         Send("hello server!!");
         UtilityHelper.RaiseEvent(OnConnectedServer, session);
     }
     else
     {
         UtilityHelper.RaiseEvent(OnConnectFail, new NineResult(Constant.CODE_CONNECT_TO_SERVER_FAIL.ToString(), "Error", "Connect to server failed!!!"));
     }
 }
Пример #2
0
 public void BeginSend(byte[] byteData, int offset, int bufferSize, SocketFlags socketFlag, AsyncCallback asyncCallback, Session session)
 {
     client.BeginSend(byteData, offset, bufferSize, socketFlag, asyncCallback, session);
 }
Пример #3
0
 private void Receive(Session session)
 {
     if (session.IsConnected)
         session.BeginReceive(session.Buffer, 0, bufferSize, 0,
             new AsyncCallback(ReceiveCallback), session);
     else
     {
         timer.Stop();
         UtilityHelper.RaiseEvent(OnDisConnectedServer, session);
     }
 }
Пример #4
0
 public void BeginReceive(byte[] buffer, int offset, int bufferSize, SocketFlags socketFlag, AsyncCallback ReadCallback, Session session)
 {
     client.BeginReceive(session.Buffer, 0, bufferSize, socketFlag, new AsyncCallback(ReadCallback), session);
 }