/// <summary> /// Creates a new TCP Server /// </summary> /// <param name="IP">IP to listen on (use 0.0.0.0 for all sockets)</param> /// <param name="Port">Port to listen on</param> public TcpServer(string IP, int Port) { Srv = new TcpListener(new IPEndPoint(IPAddress.Parse(IP), Port)); NewConnection += new NewConnectionHandler(NET_NewConnection); NewUser += new NewUserHandler(NET_NewUser); CurrentAsync = null; }
/// <summary> /// Creates a new instance with the specified options and instantly starts it. /// </summary> /// <param name="newConnectionHandler">The handler of new connections.</param> /// <param name="receiveHandler">The handler of received data.</param> /// <param name="connectionLostHandler">The handler of disconnects.</param> /// <param name="connectedSockets">A collection which always contains all connected sockets.</param> /// <param name="maxPendingConnections">The maximum count of pending connections (backlog).</param> /// <param name="port">The port the server should listen on.</param> public TcpServerSocket(NewConnectionHandler newConnectionHandler, ReceiveHandler receiveHandler, ConnectionLostHandler connectionLostHandler, ICollection <Socket> connectedSockets, int maxPendingConnections, int port) { _newConnectionHandler = newConnectionHandler; _receiveHandler = receiveHandler; _connectionLostHandler = connectionLostHandler; _connectedSockets = connectedSockets; _socket = new Socket(SocketType.Stream, ProtocolType.Tcp) { ReceiveBufferSize = DoubleProtocol.TcpSocketBufferSize, SendBufferSize = DoubleProtocol.TcpSocketBufferSize, ReceiveTimeout = DoubleProtocol.SocketOperationTimeout, SendTimeout = DoubleProtocol.SocketOperationTimeout, NoDelay = true }; _socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true); _socket.Bind(new IPEndPoint(IPAddress.IPv6Any, port)); _socket.Listen(maxPendingConnections); StartAccepting(); }
public HTTPServer() { NewConnection += new NewConnectionHandler(HTTPServer_NewConnection); S = new TcpListener(new IPEndPoint(IPAddress.Loopback, 8080)); }