private void InitiateOpenServer() { fileManagement = new FileManagement(); fileManagement.read(); RServer openServer = new RServer(fileManagement.fileData.myIpAddress, OPEN_COMMUNICATION_PORT.ToString()); openServer.setOnNewDeviceConnectedCallback( new RServer.NewDeviceConnected( (RServer _client, CommunicationNetworkStream _stream) => { //CHECK IF THIS CLIENT IS ACTUALLY WANTS TO HAVE A NEW CONNECTION string __data = _stream.ReadString(true); string[] __pp = __data.Split(':'); string requestCode = __pp[0]; switch (requestCode) { case "NEW_CONNECTION": allcoateNewConnection(_client, _stream); break; case "NEW_OR_REDIRECT_CONNECTION": //NEW_OR_REDIRECT_CONNECTION:othId if (ConnectedClients.ContainsKey(__pp[1])) { //THE CLIENT HAS AN ALREADY ALLOCATED PORT //INSTRUCT TO MOVE NetworkClient cL = ((NetworkClient)ConnectedClients[__pp[1]]); _stream.WriteString($"MOVE_TO_PORT:{cL.clientPort.ServerPort}:{cL.othId}"); Debug.WriteLine($"NEW_OR_REDIRECT_CONNECTION: redirected to port.{cL.clientPort.ServerPort}:{cL.othId}"); } else { allcoateNewConnection(_client, _stream); MessageBox.Show("NEW_OR_REDIRECT_CONNECTION: new port allocated"); } break; } } ) ); openServer.Initialize(true); }