From 17cc084b863c84cfcd563b4211c1393eb3d4ea66 Mon Sep 17 00:00:00 2001 From: nbillard Date: Mon, 13 Feb 2023 08:07:52 +0100 Subject: [PATCH] distinct address for server and client --- tsock_test_Nathan.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tsock_test_Nathan.c b/tsock_test_Nathan.c index ff74703..793ea0f 100644 --- a/tsock_test_Nathan.c +++ b/tsock_test_Nathan.c @@ -19,7 +19,8 @@ données du réseau */ /* pour la gestion des erreurs */ #include -#define DEFAULTPORT 9000 +#define DEFAULTSERVERPORT 9000 +#define DEFAULTCLIENTPORT 8999 #define MSG_LENGTH 10 #define NB_CLIENTS 1 #define TCP_BUFFER_LEN 2000 @@ -189,7 +190,11 @@ int main (int argc, char **argv) // remplissage de l'addresse locale memset(&addr_local, 0, sizeof(addr_local)); addr_local.sin_family = AF_INET; - addr_local.sin_port = DEFAULTPORT; + if (source) { + addr_local.sin_port = DEFAULTCLIENTPORT; + } else { + addr_local.sin_port = DEFAULTSERVERPORT; + } addr_local.sin_addr.s_addr = INADDR_ANY; printf("address built\n"); @@ -204,7 +209,11 @@ int main (int argc, char **argv) memset(&addr_distant, 0, sizeof(addr_local)); addr_distant.sin_family = AF_INET; - addr_distant.sin_port = DEFAULTPORT; + if (source) { + addr_local.sin_port = DEFAULTSERVERPORT; + } else { + addr_local.sin_port = DEFAULTCLIENTPORT; + } hp = gethostbyname(hostname); if (hp == NULL) { printf("hostname not found\n");