public ChatServer ( IPEndPoint service_point, string group_info_path, string chat_path, IController controller ) { Controller = controller; Connect = null; GroupInfoPath = group_info_path; ChatPath = chat_path; ServerSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); ServerSocket.Bind(service_point); Controller.SetActuallPort((ServerSocket.LocalEndPoint as IPEndPoint).Port); ServerSocket.Listen(1000); ServerSocket.BeginAccept(OnReceive, null); Controller.ServerStateChanged(ServerState.WAITING); Controller.Notify(LogLevel.Info, "已在 " + ServerSocket.LocalEndPoint + " 上启动服务"); }
private void OnReceive(IAsyncResult ar) { try { Socket main = ServerSocket.EndAccept(ar); Connect = new MainConnect ( main, GroupInfoPath, ChatPath, Controller.Notify, Close ); Controller.ServerStateChanged(ServerState.CONNECTED); Controller.Notify(LogLevel.Info, "已连接 " + main.RemoteEndPoint + " 上的远程服务"); } catch { } }