/// <summary> /// Construct a nEw MewLabs Tcp Server /// </summary> /// <param name="ip">Tye IpAddress of the server</param> /// <param name="type">The type of communication the server uses (tcp,tls,udp)</param> /// <param name="port">The port the server listens on</param> /// <param name="parser">The parser that is needed to parse the protocol send over the Tcp Communication, NUll by default will use the RawProtocol Parser</param> public NekoIOLabsServer(IPAddress ip, NEKOIOLABS_COMMUNICATION_TYPE type, int port, IProtocolParser parser = null, ILogger logger = null) { try { if (parser == null) { _protocolParser = new RawProtocolParser(); } else { _protocolParser = parser; } //check if they plugged in a logger other wise use default logger if (Logger == null) { if (logger == null) { _logger = new SimpleDebugLogger(); } else { _logger = logger; } } SetCommuncations(type, ip, port); _connectedClients = new List <NekoIOLabsConnectedClient>(); serverCommunication.OnClientConnected += ServerCommunication_OnClientConnected; } catch (Exception ex) { throw new Exception("creation of server failed"); } }
/// <summary> /// create the correct communication class /// </summary> /// <param name="type">The type of comunication that is used ex. TCP or TLS or UDP</param> private void SetCommuncations(NEKOIOLABS_COMMUNICATION_TYPE type, IPAddress ip, int?port = null) { switch (type) { case NEKOIOLABS_COMMUNICATION_TYPE.TCP: { if (port != null) { serverCommunication = new TcpCommunication(ip, (int)port); } else { serverCommunication = new TcpCommunication(ip); } break; } } }