コード例 #1
0
ファイル: SocketListener.cs プロジェクト: lvshiling/Scut
        /// <summary>
        /// Initializes a new instance
        /// </summary>
        /// <param name="socketSettings">Socket settings.</param>
        /// <param name="requestHandler"></param>
        public SocketListener(SocketSettings socketSettings, RequestHandler requestHandler)
        {
            this.socketSettings = socketSettings;
            this.requestHandler = requestHandler;
            this.bufferManager = new BufferManager(this.socketSettings.BufferSize * this.socketSettings.NumOfSaeaForRecSend, this.socketSettings.BufferSize);

            this.ioEventArgsPool = new ThreadSafeStack<SocketAsyncEventArgs>(socketSettings.NumOfSaeaForRecSend);
            this.acceptEventArgsPool = new ThreadSafeStack<SocketAsyncEventArgs>(socketSettings.MaxAcceptOps);
            this.maxConnectionsEnforcer = new Semaphore(this.socketSettings.MaxConnections, this.socketSettings.MaxConnections);
            Init();
        }
コード例 #2
0
ファイル: ClientSocket.cs プロジェクト: huangchenjun/Scut
 /// <summary>
 /// 
 /// </summary>
 /// <param name="clientSettings"></param>
 /// <param name="requestHandler"></param>
 public ClientSocket(ClientSocketSettings clientSettings, RequestHandler requestHandler)
 {
     this.clientSettings = clientSettings;
     this.requestHandler = requestHandler;
     Restart();
 }
コード例 #3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="clientSettings"></param>
 /// <param name="requestHandler"></param>
 public ClientSocket(ClientSocketSettings clientSettings, RequestHandler requestHandler)
 {
     this.clientSettings = clientSettings;
     this.requestHandler = requestHandler;
     Restart();
 }
コード例 #4
0
ファイル: GameSocketHost.cs プロジェクト: LeeWangyeol/Scut
        /// <summary>
        /// 
        /// </summary>
        protected GameSocketHost(RequestHandler requestHandler)
        {
            _setting = GameEnvironment.Setting;
            int port = _setting != null ? _setting.GamePort : 0;
            IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Any, port);

            var section = GetSection();
            int maxConnections = section.SocketMaxConnection;
            int backlog = section.SocketBacklog;
            int maxAcceptOps = section.SocketMaxAcceptOps;
            int bufferSize = section.SocketBufferSize;
            int expireInterval = section.SocketExpireInterval;
            int expireTime = section.SocketExpireTime;

            //threadPool = new SmartThreadPool(180 * 1000, 100, 5);
            //threadPool.Start();

            var socketSettings = new SocketSettings(maxConnections, backlog, maxAcceptOps, bufferSize, localEndPoint, expireInterval, expireTime);
            socketListener = new SocketListener(socketSettings, requestHandler);
            socketListener.DataReceived += new ConnectionEventHandler(socketLintener_DataReceived);
            socketListener.Connected += new ConnectionEventHandler(socketLintener_OnConnectCompleted);
            socketListener.Disconnected += new ConnectionEventHandler(socketLintener_Disconnected);

            _httpCdnAddress = new HttpCDNAddress();
            httpListener = new HttpListener();
            var httpHost = section.HttpHost;
            var httpPort = section.HttpPort;
            var httpName = section.HttpName;

            if (!string.IsNullOrEmpty(httpHost))
            {
                EnableHttp = true;
                var hosts = httpHost.Split(',');
                foreach (var point in hosts)
                {
                    var addressList = point.Split(':');
                    string host = addressList[0];
                    int hport = httpPort;
                    if (addressList.Length > 1)
                    {
                        int.TryParse(addressList[1], out hport);
                    }

                    string address = host.StartsWith("http", StringComparison.InvariantCultureIgnoreCase)
                                         ? host
                                         : "http://" + host;
                    httpListener.Prefixes.Add(string.Format("{0}:{1}/{2}/", address, hport, httpName));
                }
            }
        }
コード例 #5
0
ファイル: ClientSocket.cs プロジェクト: chayao2015/Scut
 /// <summary>
 ///
 /// </summary>
 /// <param name="clientSettings"></param>
 /// <param name="requestHandler"></param>
 public ClientSocket(ClientSocketSettings clientSettings, RequestHandler requestHandler)
 {
     this.clientSettings = clientSettings;
     this.requestHandler = requestHandler;
     socketClient        = new Socket(this.clientSettings.RemoteEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
 }