diff --git a/code/server/Server/PongServer.cs b/code/server/Server/PongServer.cs index 0e27750..b4c0c87 100644 --- a/code/server/Server/PongServer.cs +++ b/code/server/Server/PongServer.cs @@ -97,7 +97,7 @@ public class PongServer // Send port message to client - byte[] connectionData = Encoding.ASCII.GetBytes(room.Port.ToString()); + byte[] connectionData = Encoding.ASCII.GetBytes(nextPort.ToString()); serverSocket.Send(connectionData, connectionData.Length, remoteEndPoint); rooms[data.Data.playerId] = room; @@ -110,15 +110,16 @@ public class PongServer // Assign a unique port to the client - IPEndPoint clientEndPoint = new IPEndPoint(IPAddress.Any, room.Port); + IPEndPoint clientEndPoint = new IPEndPoint(IPAddress.Any, nextPort); + UdpClient clientSocket = new UdpClient(clientEndPoint); - room.playerJoin = new KeyValuePair(data.Data, room.playerHost.Value); + room.playerJoin = new KeyValuePair(data.Data, clientSocket); Console.WriteLine("New connection Client from " + remoteEndPoint.ToString()); // Send port message to client - byte[] connectionData = Encoding.ASCII.GetBytes(room.Port.ToString()); + byte[] connectionData = Encoding.ASCII.GetBytes(nextPort.ToString()); serverSocket.Send(connectionData, connectionData.Length, remoteEndPoint); room.PropertyChanged += room.OnReadyChanged; diff --git a/code/server/Server/Room.cs b/code/server/Server/Room.cs index d28cae1..893b6c0 100644 --- a/code/server/Server/Room.cs +++ b/code/server/Server/Room.cs @@ -82,18 +82,13 @@ namespace Server if (maxPlayer == 2) { - //IPEndPoint remoteEndPoint = new IPEndPoint(IPAddress.Any, 0); - //byte[] receivedData = serverSocket.Receive(ref remoteEndPoint); + IPEndPoint remoteEndPoint = new IPEndPoint(IPAddress.Any, 3133); - IPEndPoint remoteEndPointHost = new IPEndPoint(IPAddress.Any, 0); - IPEndPoint remoteEndPointJoin = new IPEndPoint(IPAddress.Any, 0); + byte[] receivedDataHost = playerHost.Value.Receive(ref remoteEndPoint); + byte[] receivedDataJoin = playerJoin.Value.Receive(ref remoteEndPoint); - - byte[] receivedDataHost = playerHost.Value.Receive(ref remoteEndPointHost); - byte[] receivedDataJoin = playerJoin.Value.Receive(ref remoteEndPointJoin); - Console.WriteLine("blabla"); - playerJoin.Value.Send(receivedDataHost, receivedDataHost.Length, remoteEndPointJoin); - playerHost.Value.Send(receivedDataJoin, receivedDataJoin.Length, remoteEndPointHost); + playerJoin.Value.Send(receivedDataHost, receivedDataHost.Length, remoteEndPoint); + playerHost.Value.Send(receivedDataJoin, receivedDataJoin.Length, remoteEndPoint); Thread receiveThread1 = new Thread(() => ReceiveMessages(playerHost.Value, playerJoin.Value));