Пример #1
0
 public void Send(byte[] buffer, int offset, int size)
 {
     if (_socket == null)
     {
         var errorMessage = "session not initialize.";
         if (ErrorHandler != null)
         {
             ErrorHandler(this, SessionErrorCode.StateError, errorMessage);
             return;
         }
         throw new Exception(errorMessage);
     }
     try
     {
         var param = new SessionParam(_socket, _ipAddress, _port);
         _socket.BeginSend(buffer, offset, size, SocketFlags.None, SendCallback, param);
     }
     catch (Exception exception)
     {
         Active = false;
         if (ErrorHandler != null)
         {
             ErrorHandler(this, SessionErrorCode.StateError, exception.Message);
             return;
         }
         throw;
     }
 }
Пример #2
0
 public void Connect(IPAddress ipAddress, int port)
 {
     Initialize(ipAddress.AddressFamily);
     _ipAddress = ipAddress;
     _port      = port;
     if (_socket == null)
     {
         var errorMessage = "initialize failure.";
         if (ErrorHandler != null)
         {
             ErrorHandler(this, SessionErrorCode.StateError, errorMessage);
             return;
         }
         throw new Exception(errorMessage);
     }
     try
     {
         var param = new SessionParam(_socket, _ipAddress, _port);
         _socket.BeginConnect(_ipAddress, _port, ConnectCallback, param);
     }
     catch (Exception exception)
     {
         if (ErrorHandler != null)
         {
             ErrorHandler(this, SessionErrorCode.StateError, exception.Message);
             return;
         }
         throw;
     }
 }
Пример #3
0
 private void OnConnected(Session session, SessionParam args)
 {
     LogHelper.Print("[NetMgr]Session Connected.");
     ProtoHelper.Register();
     if (!GameMgr.singleton.CheckUpdateState)
     {
         GameMgr.singleton.CheckUpdateState = true;
         _checkUpdateState = true;
     }
 }
Пример #4
0
 private void OnSend(Session session, int count, SessionParam args)
 {
 }