亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? socketconnector.cs

?? ActiveSync數據同步
?? CS
字號:
/* ====================================================================
 * Copyright (c) 2007 Andre Luis Azevedo (az.andrel@yahoo.com.br)
 * All rights reserved.
 *                       
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *    In addition, the source code must keep original namespace names.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution. In addition, the binary form must keep the original 
 *    namespace names and original file name.
 * 
 * 3. The name "ALAZ" or "ALAZ Library" must not be used to endorse or promote 
 *    products derived from this software without prior written permission.
 *
 * 4. Products derived from this software may not be called "ALAZ" or
 *    "ALAZ Library" nor may "ALAZ" or "ALAZ Library" appear in their 
 *    names without prior written permission of the author.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY
 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 * OF THE POSSIBILITY OF SUCH DAMAGE. 
 */

using System;
using System.Threading;
using System.Net;
using System.Net.Sockets;
using System.Text;

namespace ALAZ.SystemEx.NetEx.SocketsEx
{

    /// <summary>
    /// Client socket creator.
    /// </summary>
    public class SocketConnector : BaseSocketConnectionCreator
    {

        #region Fields

        private Socket FSocket;
        private IPEndPoint FRemoteEndPoint;

        private Timer FReconnectTimer;
        private int FReconnectAttempts;
        private int FReconnectAttemptInterval;
        private int FReconnectAttempted;

        private ProxyInfo FProxyInfo;

        #endregion

        #region Constructor

        /// <summary>
        /// Base SocketConnector creator.
        /// </summary>
        /// <param name="host">
        /// Host.
        /// </param>
        /// <param name="remoteEndPoint">
        /// The remote endpoint to connect.
        /// </param>
        /// <param name="encryptType">
        /// Encrypt type.
        /// </param>
        /// <param name="compressionType">
        /// Compression type.
        /// </param>
        /// <param name="cryptoService">
        /// CryptoService. if null, will not be used.
        /// </param>
        /// <param name="localEndPoint">
        /// Local endpoint. if null, will be any address/port.
        /// </param>
        public SocketConnector(BaseSocketConnectionHost host, string name, IPEndPoint remoteEndPoint, ProxyInfo proxyData, EncryptType encryptType, CompressionType compressionType, ICryptoService cryptoService, int reconnectAttempts, int reconnectAttemptInterval, IPEndPoint localEndPoint)
            : base(host, name, localEndPoint, encryptType, compressionType, cryptoService)
        {

            FReconnectTimer = new Timer(new TimerCallback(ReconnectSocketConnection));
            FRemoteEndPoint = remoteEndPoint;

            FReconnectAttempts = reconnectAttempts;
            FReconnectAttemptInterval = reconnectAttemptInterval;

            FReconnectAttempted = -1;

            FProxyInfo = proxyData;

        }

        #endregion

        #region Destructor

        protected override void Free(bool canAccessFinalizable)
        {

            if (FReconnectTimer != null)
            {
                FReconnectTimer.Dispose();
                FReconnectTimer = null;
            }

            if (FSocket != null)
            {
                FSocket.Close();
                FSocket = null;
            }
            
            FRemoteEndPoint = null;
            FProxyInfo = null;

            base.Free(canAccessFinalizable);

        }

        #endregion

        #region Methods

        #region InitializeConnection

        protected override void InitializeConnection(object state)
        {

          BaseSocketConnection connection = (BaseSocketConnection) state;

          if (FProxyInfo != null)
          {
            InitializeProxy(connection);
          }
          else
          {
            base.InitializeConnection(connection);
          }

        }

        #endregion

        #region InitializeProxy

        protected void InitializeProxy(BaseSocketConnection connection)
        {

          if (!Disposed)
          {

            try
            {

              if (connection.Active)
              {

                MessageBuffer mb = new MessageBuffer(0);
                mb.PacketBuffer = FProxyInfo.GetProxyRequestData(FRemoteEndPoint);
                connection.Socket.BeginSend(mb.PacketBuffer, mb.PacketOffSet, mb.PacketRemaining, SocketFlags.None, new AsyncCallback(InitializeProxySendCallback), new CallbackData(connection, mb));
              }

            }
            catch (Exception ex)
            {
              Host.FireOnException(connection, ex);
            }

          }

        }

        #endregion

        #region InitializeProxySendCallback

        private void InitializeProxySendCallback(IAsyncResult ar)
        {

            if (!Disposed)
            {

                BaseSocketConnection connection = null;
                MessageBuffer writeMessage = null;
                CallbackData callbackData = null;

                try
                {

                  callbackData = (CallbackData)ar.AsyncState;
                  connection = callbackData.Connection;
                  writeMessage = callbackData.Buffer;

                  if (connection.Active)
                  {

                    //----- Socket!
                    int writeBytes = connection.Socket.EndSend(ar);

                    if (writeBytes < writeMessage.PacketRemaining)
                    {
                      //----- Continue to send until all bytes are sent!
                      writeMessage.PacketOffSet += writeBytes;
                      connection.Socket.BeginSend(writeMessage.PacketBuffer, writeMessage.PacketOffSet, writeMessage.PacketRemaining, SocketFlags.None, new AsyncCallback(InitializeProxySendCallback), callbackData);
                    }
                    else
                    {

                      writeMessage = null;
                      callbackData = null;

                      MessageBuffer readMessage = new MessageBuffer(4096);
                      connection.Socket.BeginReceive(readMessage.PacketBuffer, readMessage.PacketOffSet, readMessage.PacketRemaining, SocketFlags.None, new AsyncCallback(InitializeProxyReceiveCallback), new CallbackData(connection, readMessage));

                    }

                  }

                }
                catch (Exception ex)
                {
                  Host.FireOnException(connection, ex);
                }

            }

        }

        #endregion

        #region InitializeProxyReceiveCallback

        private void InitializeProxyReceiveCallback(IAsyncResult ar)
        {

          if (!Disposed)
          {

            BaseSocketConnection connection = null;
            MessageBuffer readMessage = null;
            CallbackData callbackData = null;

            try
            {

              callbackData = (CallbackData)ar.AsyncState;
              connection = callbackData.Connection;
              readMessage = callbackData.Buffer;

              if (connection.Active)
              {

                int readBytes = connection.Socket.EndReceive(ar);

                if (readBytes > 0)
                {

                  FProxyInfo.GetProxyResponseStatus(readMessage.PacketBuffer);

                  readMessage = null;
                  callbackData = null;

                  if (FProxyInfo.Completed)
                  {
                    base.InitializeConnection(connection);
                  }
                  else
                  {
                    InitializeProxy(connection);
                  }

                }
                else
                {
                  throw new ProxyAuthenticationException(0, "Proxy connection aborted.");
                }

              }

            }
            catch (Exception ex)
            {

                Host.FireOnException(connection, ex);

            }
          
          }

        }

        #endregion

        #region Start

        public override void Start()
        {

            if (!Disposed)
            {
                BeginConnect();
            }

        }

        #endregion

        #region BeginConnect

        /// <summary>
        /// Begin the connection with host.
        /// </summary>
        internal void BeginConnect()
        {

            FSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            FSocket.Bind(InternalLocalEndPoint);

            if (FProxyInfo == null)
            {
              FSocket.BeginConnect(FRemoteEndPoint, new AsyncCallback(BeginConnectCallback), this);
            }
            else
            {
              FProxyInfo.Completed = false;
              FProxyInfo.SOCKS5Phase = SOCKS5Phase.spIdle;
              FSocket.BeginConnect(FProxyInfo.ProxyEndPoint, new AsyncCallback(BeginConnectCallback), this);            
            }

        }

        #endregion

        #region BeginConnectCallback

        /// <summary>
        /// Connect callback!
        /// </summary>
        /// <param name="ar"></param>
        internal void BeginConnectCallback(IAsyncResult ar)
        {

            if (!Disposed)
            {

                BaseSocketConnection connection = null;
                SocketConnector connector = null;

                try
                {

                  connector = (SocketConnector) ar.AsyncState;
                  connection = new ClientSocketConnection(Host, connector, connector.Socket);

                  connector.Socket.EndConnect(ar);

                  //----- Adjust buffer size!
                  connector.Socket.ReceiveBufferSize = Host.SocketBufferSize;
                  connector.Socket.SendBufferSize = Host.SocketBufferSize;
                  
                  connection.Active = true;

                  //----- Initialize!
                  Host.AddSocketConnection(connection);
                  InitializeConnection(connection);

                }
                catch (Exception ex)
                {

                    if (ex is SocketException)
                    {

                      FReconnectAttempted++;
                      Reconnect(false, connection, ex);

                    }
                    else
                    {
                      Host.FireOnException(connection, ex);
                    }

                }

            }

        }

        #endregion

        #region Stop

        public override void Stop()
        {
            Dispose();
        }

        #endregion

        #region Reconnect

        internal void Reconnect(bool resetAttempts, BaseSocketConnection connection, Exception ex)
        {

          if (!Disposed)
          {

              if (resetAttempts)
              {
                FReconnectAttempted = 0;
              }

              if (FReconnectAttempts > 0)
              {

                if (FReconnectAttempted < FReconnectAttempts)
                {

                  Host.RemoveSocketConnection(connection);
                  Host.DisposeAndNullConnection(ref connection);

                  FReconnectTimer.Change(FReconnectAttemptInterval, FReconnectAttemptInterval);

                }
                else
                {
                  Host.FireOnException(connection, new ReconnectAttemptsException("Max reconnect attempts reached"), true);
                }

              }
              else
              {
                
                if ( (connection != null) && (ex != null) )
                {
                  Host.FireOnException(connection, ex, true);
                }

              }

           }

        }

        #endregion

        #region ReconnectSocketConnection

        private void ReconnectSocketConnection(Object stateInfo)
        {

            if (!Disposed)
            {
                FReconnectTimer.Change(Timeout.Infinite, Timeout.Infinite);
                BeginConnect();
            }

        }

        #endregion

        #endregion

        #region Properties

        public int ReconnectAttempts
        {
            get { return FReconnectAttempts; }
            set { FReconnectAttempts = value; }
        }

        public int ReconnectAttemptInterval
        {
            get { return FReconnectAttemptInterval; }
            set { FReconnectAttemptInterval = value; }
        }

        public IPEndPoint LocalEndPoint
        {
            get { return InternalLocalEndPoint; }
            set { InternalLocalEndPoint = value; }
        }

        public IPEndPoint RemoteEndPoint
        {
            get { return FRemoteEndPoint; }
        }
        
        public  ProxyInfo ProxyInfo
        {
            get { return FProxyInfo; }
            set { FProxyInfo = value; } 
        }

        internal Socket Socket
        {
            get { return FSocket; }
        }

        #endregion

    }

}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
911国产精品| 国产精品久久久久一区二区三区 | 在线看不卡av| 久久久777精品电影网影网| 亚洲一二三四区| 成人国产精品免费网站| 91精品国产手机| 亚洲一区二区三区影院| 国产91精品精华液一区二区三区 | 精品一区二区三区香蕉蜜桃| zzijzzij亚洲日本少妇熟睡| 日韩免费看的电影| 亚洲一区二区三区四区在线免费观看| 国产一区二区导航在线播放| 欧美一区日韩一区| 亚洲va国产天堂va久久en| 成人福利视频网站| 欧美电影免费提供在线观看| 午夜精品爽啪视频| 日本大香伊一区二区三区| 国产精品久久久久久妇女6080| 免费av网站大全久久| 欧美日韩国产不卡| 亚洲福利一区二区三区| 欧洲精品在线观看| 一区二区三区.www| 在线观看av一区二区| 亚洲精品伦理在线| 日本二三区不卡| 亚洲福利视频一区二区| 欧美视频你懂的| 亚洲综合在线电影| 欧美性受xxxx| 视频一区欧美精品| 欧美成人a视频| 激情综合色丁香一区二区| 欧美成人福利视频| 国产老肥熟一区二区三区| 久久久久久久久久久99999| 国产美女精品在线| 国产精品美女久久久久aⅴ国产馆 国产精品美女久久久久av爽李琼 国产精品美女久久久久高潮 | 亚洲午夜激情av| 欧美日韩一卡二卡| 亚洲成人黄色影院| 678五月天丁香亚洲综合网| 美女免费视频一区| 亚洲国产精品精华液2区45| 国产sm精品调教视频网站| 亚洲欧洲日韩女同| 7777精品伊人久久久大香线蕉最新版| 亚洲国产日韩一级| 精品播放一区二区| 成人精品小蝌蚪| 亚洲精品国产高清久久伦理二区| 欧美午夜不卡视频| 国产一区啦啦啦在线观看| 国产精品初高中害羞小美女文| 色天使久久综合网天天| 青青草一区二区三区| 久久久久久久久久看片| 色呦呦国产精品| 美女脱光内衣内裤视频久久网站 | 成人午夜又粗又硬又大| 亚洲一区在线免费观看| 26uuu精品一区二区在线观看| 高清国产午夜精品久久久久久| 亚洲欧美另类小说视频| 日韩精品一区二区三区中文不卡| 国产成人免费网站| 亚洲成人av电影| 国产欧美一区二区在线观看| 欧美无砖专区一中文字| 国产成人在线视频网站| 亚洲va欧美va人人爽午夜| 国产午夜精品在线观看| 欧美日韩国产精品成人| 国产东北露脸精品视频| 首页亚洲欧美制服丝腿| 国产精品久久久久婷婷二区次| 欧美日韩一区久久| 成人午夜私人影院| 美日韩一区二区| 一级精品视频在线观看宜春院| 久久综合久久99| 欧美剧情片在线观看| 成人av在线播放网站| 蜜桃视频一区二区三区在线观看| 亚洲精品国产精品乱码不99| 国产欧美精品一区二区色综合| 欧美人与性动xxxx| 91麻豆精品秘密| 国产成a人亚洲精品| 青青草一区二区三区| 亚洲综合一区在线| 中文字幕一区二区在线播放| 国产偷国产偷精品高清尤物| 日韩欧美一区二区久久婷婷| 欧美日韩精品一二三区| 在线视频综合导航| 成人高清免费观看| 国产成人丝袜美腿| 国内国产精品久久| 国产一区二区三区免费在线观看| 欧美aaaaaa午夜精品| 五月天激情综合| 天天影视网天天综合色在线播放| 亚洲色图欧洲色图| 亚洲欧洲av在线| 国产精品电影一区二区| 国产精品亲子伦对白| 欧美韩日一区二区三区| 国产日韩欧美精品电影三级在线 | 欧美日本免费一区二区三区| 日本高清不卡aⅴ免费网站| 99精品久久99久久久久| 成人高清免费在线播放| av不卡免费电影| 色综合天天综合| 欧洲国内综合视频| 欧美日韩三级在线| 欧美一区二区三区视频在线| 日韩免费福利电影在线观看| 日韩欧美一卡二卡| 国产无人区一区二区三区| 国产丝袜在线精品| 亚洲日本乱码在线观看| 亚洲欧美日韩一区| 亚洲国产一区二区a毛片| 午夜精品福利久久久| 丝袜美腿亚洲色图| 久久精品国产色蜜蜜麻豆| 国产一区欧美二区| 97久久精品人人做人人爽| 91黄色免费版| 日韩美女一区二区三区| 久久九九全国免费| 一区二区三区不卡在线观看| 日本美女一区二区三区| 国产精品白丝av| 91黄色在线观看| 精品粉嫩超白一线天av| 亚洲国产精品成人综合| 亚洲午夜在线视频| 精品一二三四区| 99麻豆久久久国产精品免费| 欧美午夜精品电影| 久久综合色婷婷| 一区二区成人在线| 国产伦理精品不卡| 在线观看欧美黄色| 久久久久久久一区| 亚洲高清免费观看| 丰满放荡岳乱妇91ww| 欧美高清www午色夜在线视频| 2019国产精品| 午夜国产精品一区| 国产成人av电影免费在线观看| 日本韩国欧美三级| 国产日产精品1区| 天天综合色天天综合| 成人综合婷婷国产精品久久蜜臀| 欧美色区777第一页| 亚洲国产精品精华液ab| 青青草国产精品亚洲专区无| 成人av在线一区二区三区| 日韩欧美色综合| 一区二区三区色| 成人黄页毛片网站| 精品久久人人做人人爰| 亚洲成人777| 99精品久久只有精品| 久久精品网站免费观看| 日韩精品视频网| 在线一区二区三区做爰视频网站| 久久久五月婷婷| 久草这里只有精品视频| 欧美色网一区二区| 17c精品麻豆一区二区免费| 国产精品一区二区三区99| 日韩女同互慰一区二区| 婷婷亚洲久悠悠色悠在线播放| av午夜精品一区二区三区| 国产欧美日本一区视频| 精品一区二区日韩| 精品成人免费观看| 久久国产福利国产秒拍| 欧美精品v国产精品v日韩精品| 亚洲区小说区图片区qvod| 国产91清纯白嫩初高中在线观看| 日韩免费电影一区| 九九视频精品免费| 欧美精品一区二区三区蜜桃视频 | 亚洲视频一二三| 丁香亚洲综合激情啪啪综合| 精品对白一区国产伦| 久久黄色级2电影| 精品久久一区二区| 国内精品免费在线观看| 久久蜜臀精品av| 成人免费毛片a|