private void Accept() { if (!IsRunning) { OnAcceptCompletedEvent?.Invoke(string.Empty, SocketServerResult.ServerNotRunning); return; } _socket.BeginAccept(OnAcceptCallback, _socket); }
private void OnAcceptCallback(IAsyncResult result) { string ip = string.Empty; SocketServerResult sRes = SocketServerResult.None; try { Socket socket = result.AsyncState as Socket; Socket clientSocket = socket.EndAccept(result); ip = (clientSocket.RemoteEndPoint as IPEndPoint)?.Address?.ToString(); if (!string.IsNullOrEmpty(ip)) { IClientSocket cSocket = new ClientSocket(clientSocket); this[ip] = cSocket; Receive(ip); sRes = SocketServerResult.Success; } else { throw new Exception("<Ming> ## Uni Excption ## Cls:TcpSocketServer Func:OnAcceptCallback Info:Accept ip is null"); } } catch { sRes = SocketServerResult.Exception; } finally { OnAcceptCompletedEvent?.Invoke(ip, sRes); Accept(); } }