From babff8b5b03e73c6089b2738d962378851b3f639 Mon Sep 17 00:00:00 2001 From: Hugo LIVET Date: Mon, 27 Mar 2023 15:20:40 +0200 Subject: [PATCH] =?UTF-8?q?Serv=20r=C3=A9parer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- code/server/Server/PongServer.cs | 9 +++------ code/server/Server/Room.cs | 16 +++++++++------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/code/server/Server/PongServer.cs b/code/server/Server/PongServer.cs index b4c0c87..7bc2121 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(nextPort.ToString()); + byte[] connectionData = Encoding.ASCII.GetBytes(room.Port.ToString()); serverSocket.Send(connectionData, connectionData.Length, remoteEndPoint); rooms[data.Data.playerId] = room; @@ -109,17 +109,14 @@ public class PongServer { - // Assign a unique port to the client - IPEndPoint clientEndPoint = new IPEndPoint(IPAddress.Any, nextPort); - UdpClient clientSocket = new UdpClient(clientEndPoint); - room.playerJoin = new KeyValuePair(data.Data, clientSocket); + room.playerJoin = new KeyValuePair(data.Data, room.playerHost.Value); Console.WriteLine("New connection Client from " + remoteEndPoint.ToString()); // Send port message to client - byte[] connectionData = Encoding.ASCII.GetBytes(nextPort.ToString()); + byte[] connectionData = Encoding.ASCII.GetBytes(room.Port.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 893b6c0..a075ad3 100644 --- a/code/server/Server/Room.cs +++ b/code/server/Server/Room.cs @@ -73,8 +73,8 @@ namespace Server public void OnReadyChanged(object sender, PropertyChangedEventArgs e) { - Room nbPlayer = sender as Room; - int maxPlayer = nbPlayer.nbPlayer; + Room room = sender as Room; + int maxPlayer = room.nbPlayer; //IPEndPoint serverEndPoint = new IPEndPoint(IPAddress.Any, Port); //UdpClient serverSocket = new UdpClient(serverEndPoint); @@ -82,13 +82,15 @@ namespace Server if (maxPlayer == 2) { - IPEndPoint remoteEndPoint = new IPEndPoint(IPAddress.Any, 3133); + IPEndPoint remoteEndPointHost = new IPEndPoint(IPAddress.Any, room.Port); + IPEndPoint remoteEndPointJoin = new IPEndPoint(IPAddress.Any, room.Port); - byte[] receivedDataHost = playerHost.Value.Receive(ref remoteEndPoint); - byte[] receivedDataJoin = playerJoin.Value.Receive(ref remoteEndPoint); - playerJoin.Value.Send(receivedDataHost, receivedDataHost.Length, remoteEndPoint); - playerHost.Value.Send(receivedDataJoin, receivedDataJoin.Length, remoteEndPoint); + byte[] receivedDataHost = playerHost.Value.Receive(ref remoteEndPointHost); + byte[] receivedDataJoin = playerJoin.Value.Receive(ref remoteEndPointJoin); + Console.WriteLine("blabla"); + playerJoin.Value.Send(receivedDataHost, receivedDataHost.Length, remoteEndPointHost); + playerHost.Value.Send(receivedDataJoin, receivedDataJoin.Length, remoteEndPointJoin); Thread receiveThread1 = new Thread(() => ReceiveMessages(playerHost.Value, playerJoin.Value));