public void Start() { m_Server = new XSocket(); m_Server.Name = "Server"; m_Server.Listen(m_IP, m_Port, m_MaxConnection, OnAccept); m_Server.SocketLog("XSocketServer Start"); }
private void OnClientReceive(XSocket socket, byte[] buffer, int len) { var content = System.Text.Encoding.UTF8.GetString(buffer, 0, len); m_Server.SocketLog("OnClientReceive:" + socket.Index + "," + content); OnClientReceiveCallback?.Invoke(socket.Index, content); }
private void OnAccept(IAsyncResult result) { try { var server = result.AsyncState as Socket; var socket = server.EndAccept(result); var conn = new XSocket(); conn.Init(socket); conn.BeginReceive(); OnAcceptCallback?.Invoke(conn); m_Socket.BeginAccept(OnAccept, m_Socket); } catch (Exception e) { SocketLogError("XSocketServer OnAccept ERROR:" + e.Message); } }
public void Close() { m_Server.Close(); m_Server = null; }
private void OnClientClose(XSocket socket) { m_Server.SocketLog("OnClientClose:" + socket.Index); OnClientCloseCallback?.Invoke(socket.Index); }