/// <summary> /// Initializes a new instance of the <see cref="T:LibWhipLru.Server.WHIPServer"/> class. /// </summary> /// <param name="requestHandler">Request handler.</param> /// <param name="listenBacklogLength">Listen backlog length.</param> public WHIPServer( RequestReceivedDelegate requestHandler, uint listenBacklogLength ) : this(requestHandler, DEFAULT_ADDRESS, DEFAULT_PORT, DEFAULT_PASSWORD, listenBacklogLength) { // All handled elsewhere. }
public int WaitForRequest(RequestReceivedDelegate requestReceived) { int totalBytesReceived = 0; client = newSocket.Accept(); //IMPORTANT: This is a blocking call. It would sit here until data arrives. Thread.Sleep(100); int availableByteCount = 0; do { availableByteCount = client.Available; if (availableByteCount > 0) { totalBytesReceived += availableByteCount; byte[] buffer = new byte[128]; // Buffer probably should be larger than this. int readByteCount = client.Receive(buffer, 128, SocketFlags.None); string receivedStr = new string(Encoding.UTF8.GetChars(buffer)); Debug.Print(receivedStr); requestReceived(receivedStr); } } while (availableByteCount > 0); //client.Close(); // Can't close yet, we need to let caller process this request and send a Response. return(totalBytesReceived); }
/// <summary> /// Starts the web interface. /// </summary> /// <param name="port">The port the web interface is going to run on.</param> /// <param name="requestReceived">The function to call when a request is received.</param> public static void Start(int port, RequestReceivedDelegate requestReceived) { _port = port; _requestReceived = requestReceived; _running = true; _interfaceThread = new Thread(RunWebInterface); _interfaceThread.Start(); }
public Listener(RequestReceivedDelegate _requestReceived, int _port) { m_port = _port; m_requestReceived = _requestReceived; m_listeningSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); m_listeningSocket.Bind(new IPEndPoint(IPAddress.Any, m_port)); m_listeningSocket.Listen(10); }
/// <summary> /// Initializes a new instance of the <see cref="T:LibWhipLru.Server.WHIPServer"/> class. /// </summary> /// <param name="requestHandler">Request handler.</param> /// <param name="address">Address.</param> /// <param name="port">Port.</param> /// <param name="password">Password.</param> public WHIPServer( RequestReceivedDelegate requestHandler, string address, uint port, string password ) : this(requestHandler, address, port, password, DEFAULT_BACKLOG_LENGTH) { // All handled elsewhere. }
public Listener(RequestReceivedDelegate RequestReceived, int PortNumber) { portNumber = PortNumber; requestReceived = RequestReceived; listeningSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); listeningSocket.Bind(new IPEndPoint(IPAddress.Any, portNumber)); listeningSocket.Listen(10); new Thread(StartListening).Start(); }
public Listener(RequestReceivedDelegate RequestReceived, int PortNumber) { portNumber = PortNumber; requestReceived = RequestReceived; listeningSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); listeningSocket.Bind(new IPEndPoint(IPAddress.Any, portNumber)); listeningSocket.Listen(10); new Thread(StartListening).Start(); }
/// <summary> /// Initializes a new instance of the <see cref="T:LibWhipLru.Server.WHIPServer"/> class. /// </summary> /// <param name="requestHandler">Request handler.</param> /// <param name="address">Address.</param> /// <param name="port">Port.</param> /// <param name="password">Password.</param> /// <param name="listenBacklogLength">Listen backlog length.</param> public WHIPServer( RequestReceivedDelegate requestHandler, string address, uint port, string password, uint listenBacklogLength ) { LOG.Debug($"{address}:{port} - Initializing server."); IPAddress addr; if (string.IsNullOrWhiteSpace(address) || address == DEFAULT_ADDRESS) { addr = IPAddress.Any; } else { try { addr = IPAddress.Parse(address); } catch (ArgumentNullException e) { throw new ArgumentNullException("Address cannot be null.", e); } catch (FormatException e) { throw new FormatException("Address must be a valid IPv4 or IPv6 address.", e); } } _password = password; _port = (int)port; _requestHandler = requestHandler ?? throw new ArgumentNullException(nameof(requestHandler)); if (listenBacklogLength <= 0) { throw new ArgumentOutOfRangeException(nameof(listenBacklogLength), $"Value less than minimum of 1"); } else if (listenBacklogLength > int.MaxValue) { throw new ArgumentOutOfRangeException(nameof(listenBacklogLength), $"Value exceeded maximum of {int.MaxValue}"); } _listenBacklogLength = (int)listenBacklogLength; try { _localEndPoint = new IPEndPoint(addr, _port); } catch (ArgumentOutOfRangeException e) { throw new ArgumentOutOfRangeException($"Port number {_port} is invalid, should be between {IPEndPoint.MinPort} and {IPEndPoint.MaxPort}", e); } }
/// <summary> /// Initializes a new instance of the <see cref="DecodeFromContext"/> class. /// </summary> /// <param name="context">The HTTP context data received.</param> /// <param name="buildResponse">if set to <c>true</c> [sends an answer to sender].</param> /// <param name="requestReceived">Delegate for call the caller class method with recieved data.</param> public DecodeFromContext(HttpListenerContext context, bool buildResponse, RequestReceivedDelegate requestReceived) { try { mContext = context; mBuildResponse = buildResponse; mFieldsCollection = new NameValueCollection(); mRequestReceived = requestReceived; } catch (Exception ex) { EventLogger.SendMsg(ex); throw; } }
public Listener(RequestReceivedDelegate RequestReceived, int PortNumber) { portNumber = PortNumber; requestReceived = RequestReceived; listeningSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); listeningSocket.Bind(new IPEndPoint(IPAddress.Any, portNumber)); listeningSocket.Listen(10); /* * Start listener threads. Two aren't necessary, but multiple listening threads * allow multiple requests to be answered more quickly. Increase or decrease * the number of threads to your liking. */ new Thread(StartListening).Start(); // new Thread(StartListening).Start(); }
public Listener(RequestReceivedDelegate RequestReceived) : this(RequestReceived, 8080) { }
public Listener(RequestReceivedDelegate RequestReceived) //You need to set the port here too. : this(RequestReceived, 8081) { }
public Listener(RequestReceivedDelegate requestReceived, int portNumber) { _portNumber = portNumber; _requestReceived = requestReceived; }
public Listener(RequestReceivedDelegate RequestReceived) : this(RequestReceived, 80) { }
/// <summary> /// Initializes a new instance of the <see cref="T:LibWhipLru.Server.WHIPServer"/> class. /// </summary> /// <param name="requestHandler">Request handler.</param> public WHIPServer( RequestReceivedDelegate requestHandler ) : this(requestHandler, DEFAULT_ADDRESS, DEFAULT_PORT, DEFAULT_PASSWORD, DEFAULT_BACKLOG_LENGTH) { // All handled elsewhere. }