public void Close(bool isEvent = true) { if (_socket != null) { RemoveEvent(); if (_socket.State == Core.Net.Sockets.SocketState.Connected) { try { _socket.Close("Just Close"); _socket = null; } catch (Exception e) { Log.Debug(e.Message); } } if (isEvent) { EventManager.instance.DispatchEvent(this, SocketEvent.SOCKET_CLOSE); } } }
public void Dispose() { if (_socket.State == SocketState.Connected) _socket.Close("Dispose"); _socket = null; }
public void Connect(string ip, int port) { try { if (_socket != null) { Close(false); } _socket = new NetClient(); AddEvent(); _ip = ip; _port = port; _readOffset = 0; _writeOffset = 0; _socket.Connect(new System.Net.IPEndPoint(System.Net.IPAddress.Parse(ip), port)); } catch(Exception error) { EventManager.instance.DispatchEvent(this, SocketEvent.SOCKET_ERROR, error.Message); } }