System.Net.EndPointListener.BindContext C# (CSharp) Method

BindContext() public method

public BindContext ( HttpListenerContext context ) : bool
context HttpListenerContext
return bool
		public bool BindContext (HttpListenerContext context)
		{
			HttpListenerRequest req = context.Request;
			ListenerPrefix prefix;
			HttpListener listener = SearchListener (req.UserHostName, req.Url, out prefix);
			if (listener == null)
				return false;

			context.Listener = listener;
			context.Connection.Prefix = prefix;
			listener.RegisterContext (context);
			return true;
		}

Usage Example

Example #1
0
        void OnRead(IAsyncResult ares)
        {
            timer.Change(Timeout.Infinite, Timeout.Infinite);
            HttpConnection cnc   = (HttpConnection)ares.AsyncState;
            int            nread = -1;

            try {
                nread = stream.EndRead(ares);
                ms.Write(buffer, 0, nread);
                if (ms.Length > 32768)
                {
                    SendError("Bad request", 400);
                    Close(true);
                    return;
                }
            } catch {
                if (ms != null && ms.Length > 0)
                {
                    SendError();
                }
                if (sock != null)
                {
                    CloseSocket();
                }
                return;
            }

            if (nread == 0)
            {
                //if (ms.Length > 0)
                //	SendError (); // Why bother?
                CloseSocket();
                return;
            }

            if (ProcessInput(ms))
            {
                if (!context.HaveError)
                {
                    context.Request.FinishInitialization();
                }

                if (context.HaveError)
                {
                    SendError();
                    Close(true);
                    return;
                }

                if (!epl.BindContext(context))
                {
                    SendError("Invalid host", 400);
                    Close(true);
                }
                context_bound = true;
                return;
            }
            stream.BeginRead(buffer, 0, BufferSize, OnRead, cnc);
        }
All Usage Examples Of System.Net.EndPointListener::BindContext