forked from s444341/Projekt_SIK
Zaktualizuj 'server/server.c'
This commit is contained in:
parent
a4c9d7c72e
commit
dab08afc82
@ -63,6 +63,7 @@ int main(void) {
|
|||||||
|
|
||||||
//NASŁUCHIWANIE KLIENTÓW
|
//NASŁUCHIWANIE KLIENTÓW
|
||||||
while (1) {
|
while (1) {
|
||||||
|
printf("-------------/nKolejna Iteracja\n--------------\n");
|
||||||
//Aktualizacja deskryptorów
|
//Aktualizacja deskryptorów
|
||||||
max_fd = 0;
|
max_fd = 0;
|
||||||
FD_ZERO(&Clients);
|
FD_ZERO(&Clients);
|
||||||
@ -73,10 +74,13 @@ int main(void) {
|
|||||||
|
|
||||||
//Sprawdzenie Poprawności
|
//Sprawdzenie Poprawności
|
||||||
//printf("Przed Select\n");
|
//printf("Przed Select\n");
|
||||||
|
printf("Rozpoczecie:Select 1\n");
|
||||||
if(select(socket_bind+1, &Socket, NULL, NULL, NULL) > 0) {
|
if(select(socket_bind+1, &Socket, NULL, NULL, NULL) > 0) {
|
||||||
if (FD_ISSET(socket_bind, &Socket)) {
|
if (FD_ISSET(socket_bind, &Socket)) {
|
||||||
temp_accept = accept(socket_bind, (struct sockaddr*) &client[i].accept_adr, &dl);
|
temp_accept = accept(socket_bind, (struct sockaddr*) &client[i].accept_adr, &dl);
|
||||||
|
printf("Temp Accept: %i\n", temp_accept);
|
||||||
for(i=0;i<=4;i++){
|
for(i=0;i<=4;i++){
|
||||||
|
printf("Accept %i: %i\n", i, temp_accept);
|
||||||
if (client[i].socket == temp_accept){
|
if (client[i].socket == temp_accept){
|
||||||
recv(client[i].socket, msg, 1024, 0);
|
recv(client[i].socket, msg, 1024, 0);
|
||||||
break;
|
break;
|
||||||
@ -86,6 +90,7 @@ int main(void) {
|
|||||||
for(i=0;i<=4;i++){
|
for(i=0;i<=4;i++){
|
||||||
if (client[i].socket == 0){
|
if (client[i].socket == 0){
|
||||||
client[i].socket = accept(socket_bind, (struct sockaddr*) &client[i].accept_adr, &dl);
|
client[i].socket = accept(socket_bind, (struct sockaddr*) &client[i].accept_adr, &dl);
|
||||||
|
recv(client[i].socket, msg, 1024, 0);
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
printf("Miejsce %i zajęte\n", i);
|
printf("Miejsce %i zajęte\n", i);
|
||||||
@ -94,7 +99,9 @@ int main(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
printf("Koniec:Select 1\n");
|
||||||
//Set Clients
|
//Set Clients
|
||||||
|
printf("Rozpoczęcie: Set Clients\n");
|
||||||
for(i =0; i<=4; i++){
|
for(i =0; i<=4; i++){
|
||||||
|
|
||||||
if (client[i].socket > 0) {
|
if (client[i].socket > 0) {
|
||||||
@ -104,22 +111,24 @@ int main(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
printf("Koniec: Set Clients\n");
|
||||||
printf("Wiadomość:%s\n", msg);
|
printf("Wiadomość:%s\n", msg);
|
||||||
//PRZETWARZANIE WIADOMOŚCI
|
//PRZETWARZANIE WIADOMOŚCI
|
||||||
|
printf("Rozpoczecie:Select 2\n");
|
||||||
if(select(max_fd+1, NULL, &Clients, NULL, NULL) > 0) {
|
if(select(max_fd+1, NULL, &Clients, NULL, NULL) > 0) {
|
||||||
|
|
||||||
for(i=0;i<=4;i++){
|
for(i=0;i<=4;i++){
|
||||||
if (FD_ISSET(client[i].socket, &Clients)) {
|
if (FD_ISSET(client[i].socket, &Clients)) {
|
||||||
for(j=0;j<=4;j++) {
|
for(j=0;j<=4;j++) {
|
||||||
if(i!=j && client[j].socket!=0) {
|
if(i!=j && client[j].socket!=0) {
|
||||||
send(client[j].socket, &msg, 1024, 0);
|
send(client[j].socket, msg, 1024, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
printf("Koniec:Select 2\n");
|
||||||
/*for(i = 0; i<=4; i++)
|
/*for(i = 0; i<=4; i++)
|
||||||
{
|
{
|
||||||
if(client[i].socket != 0 && FD_ISSET(client[i].socket, &Clients))
|
if(client[i].socket != 0 && FD_ISSET(client[i].socket, &Clients))
|
||||||
|
Loading…
Reference in New Issue
Block a user