Example #1
0
        /** 发送到连接(主线程) */
        public void send(BaseRequest request, bool needLog)
        {
            int mid = request.getDataID();

            if (ShineSetting.needShowMessage && needLog)
            {
                Ctrl.debugLog("发消息:", "mid:" + mid, ShineSetting.needShowMessageDetail ? request.toDataString() : request.getDataClassName());
            }

            //可发送 并且消息绑定通过
            if (checkRequestNeedSend(request) && _server.checkRequestBind(mid))
            {
                sendRequestForIO(request);
            }
        }
Example #2
0
        /** 执行response们(主线程) */
        private void toRunResponseOne(BaseResponse response)
        {
            int mid = response.getDataID();

            if (ShineSetting.needShowMessage && !BytesControl.isIgnoreMessage(mid))
            {
                Ctrl.debugLog("收消息:", "mid:" + mid, ShineSetting.needShowMessageDetail ? response.toDataString() : response.getDataClassName());
            }

            _server.checkResponseUnbind(mid);

            try
            {
                response.run();
            }
            catch (Exception e)
            {
                Ctrl.errorLogForIO(e);
            }
        }
Example #3
0
        private void toGetDNS()
        {
            _state       = Connecting;
            _connectTime = 0;

            int index = ++_doIndex;

            _currentInfo = _ipInfoDic.get(_host);

            if (_currentInfo != null)
            {
                preConnectAfterAddress();
            }
            else
            {
                IPAddress address;

                if (!IPAddress.TryParse(_host, out address))
                {
                    Ctrl.debugLog("dns上");

                    Dns.BeginGetHostAddresses(_host, v =>
                    {
                        IPAddress[] addresses = null;

                        try
                        {
                            addresses = Dns.EndGetHostAddresses(v);
                        }
                        catch (Exception e)
                        {
                            Ctrl.printExceptionForIO(e);
                        }

                        ThreadControl.addMainFunc(() =>
                        {
                            if (index == _doIndex)
                            {
                                if (addresses != null)
                                {
                                    foreach (IPAddress ipAddress in addresses)
                                    {
                                        Ctrl.print("dns看收到的上地址", ipAddress);
                                    }

                                    _currentInfo = registIPInfo(_host, addresses);
                                    preConnectAfterAddress();
                                }
                                else
                                {
                                    Ctrl.printForIO("解析dns失败");
                                }
                            }
                            else
                            {
                                Ctrl.print("dns获取完,已经到下个index");
                            }
                        });
                    }, null);
                }
                else
                {
                    Ctrl.debugLog("dns下");
                    _currentInfo = registIPInfo(_host, new[] { address });
                    preConnectAfterAddress();
                }
            }
        }