Example #1
0
        public CloudServer
        (
            IPEndPoint service_point,
            string info_root_path,
            string file_root_path,
            IController controller
        )
        {
            Connect = null;

            Controller   = controller;
            InfoRootPath = info_root_path;
            FileRootPath = file_root_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 + " 上启动服务");
        }
Example #2
0
 private void OnReceive(IAsyncResult ar)
 {
     try
     {
         Socket main = ServerSocket.EndAccept(ar);
         Connect = new MainConnect
                   (
             main,
             InfoRootPath,
             FileRootPath,
             Controller.Notify,
             Close
                   );
         Controller.ServerStateChanged(ServerState.CONNECTED);
         Controller.Notify(LogLevel.Info, "已连接 " + main.RemoteEndPoint + " 上的远程服务");
     }
     catch
     {
     }
 }