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; } }
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); }
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(); }
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; } }
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; } }
private void OnConnected(Session session, SessionParam args) { LogUtil.LogUtility.Print(string.Format("[NetMgr]Session Connected!")); ProtoRegister.Register(); }
private void OnSend(Session session, int count, SessionParam args) { }