/// <summary> /// <see cref="HttpConnection"/> examples /// </summary> private static void HttpConnectionExample() { // Create an HTTP connection var httpConnection = new HttpConnection("/foo") { // Setup the close event handler mOnClose = (data) => { Console.WriteLine(data); }, // Setup the data received event handler mOnReceive = HttpConnection_OnReceive }; // Start the connection httpConnection.Start().Then( onfulfilled: () => { // Get the features var features = httpConnection.mFeatures; // Send a message httpConnection.Send("hello").Then( onfulfilled: () => { // Stop the connection httpConnection.Stop(); }, onrejected: null); }, onrejected: null); }
public HttpConnection Connect(TransferFormat transferFormat) { var connection = new HttpConnection(_httpConnectionOptions); try { connection.Start(transferFormat); return(connection); } catch { // Make sure the connection is disposed, in case it allocated any resources before failing. connection.Dispose(); throw; } }
protected override void Run() { this._listener.Start(); while (true) { try { TcpClient client = this._listener.AcceptTcpClient(); HttpConnection connection = new HttpConnection(this, client); lock (this._requests) { this._requests.Add(connection); } connection.Start(); } catch { } } }
public virtual void OnAccept( IAsyncResult ar ) { try { Socket newSocket = listenSocket.EndAccept( ar ); if ( newSocket != null ) { HttpConnection newClient = new HttpConnection( newSocket, new RemoveClientDelegate( this.RemoveClient ) ); clients.Add( newClient ); newClient.Start(); } } catch {} try { listenSocket.BeginAccept( new AsyncCallback( this.OnAccept ), listenSocket ); } catch { Dispose(); } }