public NetworkContext(Socket socket, BaseCrypto crypto)
 {
     if (socket == null)
     {
         throw new ArgumentNullException("socket");
     }
     if (crypto == null)
     {
         throw new ArgumentNullException("crypto");
     }
     this._isOpen          = true;
     this._socket          = socket;
     this._crypto          = crypto;
     this._inputQueue      = new InputQueue();
     this._outputQueue     = new OutputQueue((IBufferPolicy) new BufferAllocator(512));
     this._receiveBuffer   = new byte[2048];
     this._sendCallback    = new AsyncCallback(this.OnSend);
     this._receiveCallback = new AsyncCallback(this.OnReceive);
     this.Receive();
 }
Exemple #2
0
 public static bool Connect(BaseCrypto cryptoProvider, IPEndPoint ipEndPoint)
 {
     if (cryptoProvider == null)
     {
         throw new ArgumentNullException("cryptoProvider");
     }
     if (ipEndPoint == null)
     {
         throw new ArgumentNullException("ipEndPoint");
     }
     Network.Disconnect();
     try
     {
         Socket socket = new Socket(ipEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
         try
         {
             socket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.Debug, true);
         }
         catch (Exception ex)
         {
             Debug.Trace("SetSocketOption failed.");
             Debug.Error(ex);
         }
         Network.ProcessAsyncConnect(socket, socket.BeginConnect((EndPoint)ipEndPoint, (AsyncCallback)null, (object)null));
         Network._networkContext = new NetworkContext(socket, cryptoProvider);
         Network._networkContext.ConnectionLostCallback = (Callback)(() =>
         {
             Gumps.MessageBoxOk("Connection lost", true, new OnClick(Engine.DestroyDialogShowAcctLogin_OnClick));
             Network._networkContext = (NetworkContext)null;
             Cursor.Hourglass = false;
             Engine.amMoving = false;
         });
         return(true);
     }
     catch (SocketException ex)
     {
         return(false);
     }
 }