private void OnReceive(IAsyncResult ar) { try { Socket main = ServerSocket.EndAccept(ar); Connect = new MainConnect ( main, SQLDB, UserInfoPath, GroupInfoPath, AppliesInfoPath, ChatPath, CloudPath, CloudInfoPath, Controller.Notify, Close ); Controller.ServerStateChanged(ServerState.CONNECTED); Controller.Notify(LogLevel.Info, "已连接 " + main.RemoteEndPoint + " 上的远程服务"); } catch { } }
public LoginServer ( IPEndPoint service_point, string user_info_path, string group_info_path, string applies_info_path, string chat_path, string cloud_path, string cloud_info_path, IController controller ) { Controller = controller; Connect = null; try { SQLDB = new SQLDataBase(DBStaticData.DataBaseConnString); SQLDB.Open(); } catch (Exception e) { throw e; } UserInfoPath = user_info_path; GroupInfoPath = group_info_path; AppliesInfoPath = applies_info_path; ChatPath = chat_path; CloudPath = cloud_path; CloudInfoPath = cloud_info_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 + " 上启动服务"); }