Ejemplo n.º 1
0
 public void Send(byte[] buffer, int offset, int size)
 {
     if (_socket == null)
     {
         string errorMessage = "session not initialize.";
         if (ErrorHandler != null)
         {
             ErrorHandler(this, SessionErrorCode.StateError, errorMessage);
             return;
         }
         throw new Exception(errorMessage);
     }
     try
     {
         SessionParam 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;
     }
 }
Ejemplo n.º 2
0
        private void SendCallback(IAsyncResult ar)
        {
            SessionParam param = (SessionParam)ar.AsyncState;

            int bytesSent = 0;

            try
            {
                bytesSent = param.socket.EndSend(ar);
            }
            catch (ObjectDisposedException)
            {
                return;
            }
            catch (Exception exception)
            {
                Active = false;
                if (ErrorHandler != null)
                {
                    ErrorHandler(this, SessionErrorCode.SendError, exception.Message);
                    return;
                }

                throw;
            }
            SendHandler?.Invoke(this, bytesSent, param);
        }
Ejemplo n.º 3
0
        private void ConnectCallback(IAsyncResult ar)
        {
            SessionParam param = (SessionParam)ar.AsyncState;

            try
            {
                param.socket.EndConnect(ar);
            }
            catch (ObjectDisposedException)
            {
                return;
            }
            catch (Exception exception)
            {
                Active = false;
                if (ErrorHandler != null)
                {
                    ErrorHandler(this, SessionErrorCode.ConnectError, exception.Message);
                    return;
                }
                throw;
            }
            Active = true;
            ConnectedHandler?.Invoke(this, param);
            Receive();
        }
Ejemplo n.º 4
0
 public void Connect(IPAddress ipAddress, int port)
 {
     Initialize(ipAddress.AddressFamily);
     _ipAddress = ipAddress;
     _port      = port;
     if (_socket == null)
     {
         string errorMessage = "initialize failure.";
         if (ErrorHandler != null)
         {
             ErrorHandler(this, SessionErrorCode.StateError, errorMessage);
             return;
         }
         throw new Exception(errorMessage);
     }
     try
     {
         SessionParam 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;
     }
 }
Ejemplo n.º 5
0
 private void OnConnected(Session session, SessionParam args)
 {
     LogHelper.Print(string.Format("[NetMgr]Session Connected!"));
     ProtoHelper.Register();
     if (!GameMgr.Instance.CheckUpdateState)
     {
         GameMgr.Instance.CheckUpdateState = true;
         _checkUpdateState = true;
     }
 }
Ejemplo n.º 6
0
 private void OnConnected(Session session, SessionParam args)
 {
     LogUtil.LogUtility.Print(string.Format("[NetMgr]Session Connected!"));
     ProtoRegister.Register();
 }
Ejemplo n.º 7
0
 private void OnSend(Session session, int count, SessionParam args)
 {
 }