コード例 #1
0
        /// <summary>
        /// Begins an asynchronous read operation that reads data from the stream and stores
        /// it in the specified array.
        /// </summary>
        /// <param name="args">A user-defined object that contains information about the read
        /// operation. This object is passed to the asyncCallback delegate when the operation
        /// completes.</param>
        /// <returns>Return true if state of receive is success.</returns>
        public bool ReceiveAsync(SocketAsyncEventArgsExt args)
        {
            if (_isSecure)
            {
                _sslStream.BeginRead(args.Buffer, args.Offset, args.Count, ReceiveComplete, args);
                return(true);
            }

            return(_socket.ReceiveAsync(args));
        }
コード例 #2
0
 private void ProcessConnectCompleted(bool synchronous)
 {
     this.sendArgs.Completed -= this.OnTcpConnectCompleted;
     if (this.sendArgs.SocketError == SocketError.Success)
     {
         this.receiveArgs            = new SocketAsyncEventArgsExt();
         this.receiveArgs.Completed += this.OnReceiveCompleted;
         this.sendArgs.Completed    -= this.OnTcpConnectCompleted;
         this.sendArgs.Completed    += this.OnSendCompleted;
         this.StartWebSocketHandshake(_customHeaders);                 // this is the entry point to a version specific derived class
     }
     else
     {
         this.FailWebSocketConnection(this.sendArgs.ConnectByNameError, synchronous);
     }
 }
コード例 #3
0
        public void Start(Dictionary <string, string> customHeaders)
        {
            if (customHeaders != null)
            {
                this._customHeaders = customHeaders;
            }

            this.sendArgs = new SocketAsyncEventArgsExt();
            this.sendArgs.RemoteEndPoint = new DnsEndPoint(this.Uri.DnsSafeHost, this.Uri.Port);
#if !SILVERLIGHT
#else
            this.sendArgs.SocketClientAccessPolicyProtocol = SocketClientAccessPolicyProtocol.Http;
#endif
            this.sendArgs.Completed += this.OnTcpConnectCompleted;
            this.socket              = new SecureSocketProxy("wss".Equals(Uri.Scheme, StringComparison.OrdinalIgnoreCase));
            this.socket.NoDelay      = this.noDelay;

            if (!this.socket.ConnectAsync(this.sendArgs))
            {
                this.ProcessConnectCompleted(true);
            }
        }