Bonjour à tous,
J'ai un petit soucis lors du cast d'une structure, je ne vois pas comment faire 
En fait je tente de faire un serveur multi-clients, le client.c s'occupe de "declarer" un nouveau client au serveur...
Ces codes ne concernent que le serveur.
1 2 3 4 5 6 7 8 9
|
/*main.c*/
for(;;)
{
argc = Serveur(SERVEUR_LISTEN, 0);
Serveur(SERVEUR_ACCEPT, &argc);
}
//argc recupere (int)Clients[Id];
//voir client.c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
/*serveur.c*/
int Serveur(int sc, int pa)
{
switch(sc)
{
case SERVEUR_ACCEPT:
//La fonction accepte la connection d'un socket clients sur le socket serveur
if((((t_Clients)&pa).ClientSock = accept(serveur.ServeurSock, (SOCKADDR *)&((t_Clients)pa).ClientsSin, &((t_Clients)pa).SinSize)) == INVALID_SOCKET)
{
Fin("Echec de la connection du clients.\n");
}
else
{
printf("\nNouvelle connexion : %s se connecte.\n", inet_ntoa(((t_Clients)pa).ClientsSin.sin_addr));
strcpy(*Buff, "-- Bienvenue sur le serveur");
send(((t_Clients)pa).ClientsSock, *Buff, (int)strlen(*Buff), 0);
}
break;
}
} |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
t_Clients *Clients;
/*client.c*/
int Client(int sc, int pa)
{
switch(sc)
{
case CLIENT_NEW:
puts("Creation d'un nouveau client.");
Id++;
Clients[Id].SinSize = sizeof(Clients[Id].ClientSin);
return (int)Clients[Id];
break;
}
} |
Mon problème se pose au niveau du serveur.c, notamment ici :
if((((t_Clients)&pa).ClientSock
Partager