1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
| \\SERVEUR
#include <winsock2.h>
typedef int socklen_t;
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#define PORT 23
int main(void)
{
WSADATA WSAData;
int erreur = WSAStartup(MAKEWORD(2,2), &WSAData);
int continuer=1;
int i;
SOCKET sock0;
SOCKADDR_IN sin0;
SOCKADDR_IN csin0;
int recsize0 = sizeof sin0;
char lettres[20]="";
char joueur1[20]="";
char joueur2[20]="";
char joueur3[20]="";
char joueur4[20]="";
int sock_err;
sock0 = socket(AF_INET, SOCK_STREAM, 0);
printf("La socket %d est maintenant ouverte en mode TCP/IP\n", sock0);
sin0.sin_addr.s_addr = htonl(INADDR_ANY);
sin0.sin_family = AF_INET;
sin0.sin_port = htons(PORT);
bind(sock0, (SOCKADDR*) &sin0, recsize0);
listen(sock0, 5);
int crecsize0 = sizeof csin0;
SOCKET csock0 = accept(sock0, (SOCKADDR *) &csin0, &crecsize0);
recv(csock0, joueur1, joueur1, 0);
printf("%s",joueur1);
closesocket(csock0);
SOCKET csock1 = accept(sock0, (SOCKADDR *) &csin0, &crecsize0);
recv(csock1, joueur2, 20, 0);
printf("%s",joueur2);
// closesocket(csock1);
SOCKET csock2 = accept(sock0, (SOCKADDR *) &csin0, &crecsize0);
recv(csock2, joueur3, 20, 0);
printf("%s\n",joueur3);
// closesocket(csock2);
SOCKET csock3 = accept(sock0, (SOCKADDR *) &csin0, &crecsize0);
recv(csock3, joueur4,20, 0);
printf("%s",joueur4);
// closesocket(csock3);
csock0;
send(csock0,joueur1,20, 0);
send(csock0,joueur2,20, 0);
send(csock0,joueur3,20, 0);
send(csock0,joueur4,20, 0);
// closesocket(csock0);
csock1;
send(csock1,joueur1,20, 0);
send(csock1,joueur2,20, 0);
send(csock1,joueur3,20, 0);
send(csock1,joueur4,20, 0);
// closesocket(csock1);
csock2;
send(csock2,joueur1,20, 0);
send(csock2,joueur2,20, 0);
send(csock2,joueur3,20, 0);
send(csock2,joueur4,20, 0);
// closesocket(csock2);
csock3;
send(csock3,joueur1,20, 0);
send(csock3,joueur2,20, 0);
send(csock3,joueur3,20, 0);
send(csock3,joueur4,20, 0);
//closesocket(csock3);
WSACleanup();
return EXIT_SUCCESS;
} |
Partager