示例#1
0
        public ListenerProxy(SocketTransponder transponder, ConnectSetting setting)
        {
            _transponder = transponder;
            _setting = setting;
            var localPoint = SocketSettings.GetHostAddress(_setting.Host, _setting.Port);
            var socketSetting = new SocketSettings(localPoint, setting.MaxPoolSize, setting.BufferSize, setting.Backlog);
            socketSetting.ContinuedTimeout = _setting.ConnectTimeout;
            socketSetting.EnableReceiveTimeout = _setting.EnableReceiveTimeout;
            socketSetting.ReceiveTimeout = _setting.ReceiveTimeout;

            _listener = new SocketListener(socketSetting);
            _listener.ConnectCompleted += OnConnectCompleted;
            _listener.ReceiveCompleted += _transponder.Receive;
            _listener.SocketSending += _transponder.OnSending;
            _listener.SocketClosing += OnSocketClosing;
            _listener.ReceiveTimeout += _transponder.OnReceiveTimeout;
            _transponder.SendCompleted += (address, data) =>
            {
                if (!_listener.PushSend(address, data))
                {
                    Console.WriteLine("发送到{0} {1}byte失败", address, data.Length);
                }
            };
            _transponder.CheckConnectedHandle += OnCheckConnected;
        }
示例#2
0
        public SocketProxy(GSConnectionManager gsConnectionManager)
        {
            this.gsConnectionManager = gsConnectionManager;

            IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Any, ListenPort);
            var socketSettings = new SocketSettings(maxConnections, backlog, maxAcceptOps, bufferSize, localEndPoint, expireInterval, expireTime);
            listener = new SocketListener(socketSettings);
            listener.DataReceived += new ConnectionEventHandler(socketLintener_DataReceived);
            listener.Connected += new ConnectionEventHandler(socketLintener_Connected);
            listener.Disconnected += new ConnectionEventHandler(socketLintener_Disconnected);
            listener.StartListen();
            TraceLog.ReleaseWrite("TCP listent is started, The port:{0}.", ListenPort);

            timer = new Timer(Check, null, proxyCheckPeriod, proxyCheckPeriod);
        }
示例#3
0
        /// <summary>
        /// 
        /// </summary>
        protected GameSocketHost()
        {
            ActionDispatcher = new ActionDispatcher();
            int port = GameEnvironment.Setting.GamePort;
            IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Any, port);

            int maxConnections = ConfigUtils.GetSetting("MaxConnections", 10000);
            int backlog = ConfigUtils.GetSetting("Backlog", 1000);
            int maxAcceptOps = ConfigUtils.GetSetting("MaxAcceptOps", 1000);
            int bufferSize = ConfigUtils.GetSetting("BufferSize", 8192);
            int expireInterval = ConfigUtils.GetSetting("ExpireInterval", 600) * 1000;
            int expireTime = ConfigUtils.GetSetting("ExpireTime", 3600) * 1000;

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

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

            httpListener = new HttpListener();
            var httpHost = ConfigUtils.GetSetting("Game.Http.Host");
            var httpPort = ConfigUtils.GetSetting("Game.Http.Port", 80);
            var httpName = ConfigUtils.GetSetting("Game.Http.Name", "Service.aspx");

            if (!string.IsNullOrEmpty(httpHost))
            {
                EnableHttp = true;
                var hosts = httpHost.Split(',');
                foreach (var host in hosts)
                {
                    string address = host.StartsWith("http", StringComparison.InvariantCultureIgnoreCase)
                                         ? host
                                         : "http://" + host;
                    httpListener.Prefixes.Add(string.Format("{0}:{1}/{2}/", address, httpPort, httpName));
                }
            }
            Interlocked.Exchange(ref _runningQueue, 1);
            queueProcessThread = new Thread(ProcessQueue);
            queueProcessThread.Start();
            _LockedQueueChecker = new Timer(LockedQueueChecker, null, 100, 100);
        }
示例#4
0
        /// <summary>
        /// 
        /// </summary>
        protected GameSocketHost()
        {
            _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);
            socketListener.DataReceived += new ConnectionEventHandler(socketLintener_DataReceived);
            socketListener.Connected += new ConnectionEventHandler(socketLintener_OnConnectCompleted);
            socketListener.Disconnected += new ConnectionEventHandler(socketLintener_Disconnected);


            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
        /// <summary>
        /// 
        /// </summary>
        /// <param name="requestHandler"></param>
        protected GameWebSocketHost(WebSocketRequestHandler 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;

            var socketSettings = new SocketSettings(maxConnections, backlog, maxAcceptOps, bufferSize, localEndPoint, expireInterval, expireTime);
            socketListener = new SocketListener(socketSettings, requestHandler);
            socketListener.DataReceived += new ConnectionEventHandler(OnDataReceived);
            socketListener.Connected += new ConnectionEventHandler(socketLintener_OnConnectCompleted);
            socketListener.Handshaked += new ConnectionEventHandler(OnHandshaked);
            socketListener.Disconnected += new ConnectionEventHandler(OnDisconnected);
            socketListener.OnPing += new ConnectionEventHandler(socketLintener_OnPing);
            socketListener.OnPong += new ConnectionEventHandler(socketLintener_OnPong);
            socketListener.OnClosedStatus += socketLintener_OnClosedStatus;
        }
示例#6
0
        public void Init()
        {
            IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Any, port);

            int maxConnections = 10000;
            int backlog = 1000;
            int maxAcceptOps = 10000;
            int bufferSize = 1024;

            var socketSettings = new SocketSettings(maxConnections, backlog, maxAcceptOps, bufferSize, localEndPoint, 0, 0);
            socketListener = new SocketListener(socketSettings);
            socketListener.Connected += OnConnectCompleted;
            socketListener.DataReceived += OnReceivedCompleted;
            socketListener.StartListen();
        }