forked from s444341/Projekt_SIK
Commit
This commit is contained in:
parent
dab08afc82
commit
590ad72d9b
@ -28,6 +28,10 @@ int main(void) {
|
||||
int j;
|
||||
char ff;
|
||||
int max_fd;
|
||||
struct timeval timeout;
|
||||
timeout.tv_sec = 1;
|
||||
timeout.tv_usec = 0;
|
||||
|
||||
//Inicjalizacja Tablicy Klientów
|
||||
for(i=0; i<=4; i++)
|
||||
{
|
||||
@ -63,7 +67,7 @@ int main(void) {
|
||||
|
||||
//NASŁUCHIWANIE KLIENTÓW
|
||||
while (1) {
|
||||
printf("-------------/nKolejna Iteracja\n--------------\n");
|
||||
//printf("-------------\nKolejna Iteracja\n--------------\n");
|
||||
//Aktualizacja deskryptorów
|
||||
max_fd = 0;
|
||||
FD_ZERO(&Clients);
|
||||
@ -74,34 +78,35 @@ int main(void) {
|
||||
|
||||
//Sprawdzenie Poprawności
|
||||
//printf("Przed Select\n");
|
||||
printf("Rozpoczecie:Select 1\n");
|
||||
if(select(socket_bind+1, &Socket, NULL, NULL, NULL) > 0) {
|
||||
//printf("Rozpoczecie:Select 1\n");
|
||||
if(select(socket_bind+1, &Socket, NULL, NULL, &timeout) > 0) {
|
||||
if (FD_ISSET(socket_bind, &Socket)) {
|
||||
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++){
|
||||
printf("Accept %i: %i\n", i, temp_accept);
|
||||
if (client[i].socket == temp_accept){
|
||||
recv(client[i].socket, msg, 1024, 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(i>4) {
|
||||
//printf("Temp Accept: %i\n", temp_accept
|
||||
//printf("Sprawdzam Clienta %i: %i\n", i, client[i].socket);
|
||||
for(i=0;i<=4;i++){
|
||||
//printf("Miejsce %i: %i\n", i, client[i].socket);
|
||||
if (client[i].socket == 0){
|
||||
client[i].socket = accept(socket_bind, (struct sockaddr*) &client[i].accept_adr, &dl);
|
||||
recv(client[i].socket, msg, 1024, 0);
|
||||
client[i].socket = temp_accept;
|
||||
//recv(client[i].socket, msg, 1024, 0);
|
||||
//printf("Wiadomosc: %s\n", msg);
|
||||
break;
|
||||
} else {
|
||||
printf("Miejsce %i zajęte\n", i);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
for(i=0;i<=4;i++) {
|
||||
while(recv(client[i].socket, msg, 1024, 0)>0) {
|
||||
printf("Wiadomosc: %s\n", msg);
|
||||
}
|
||||
printf("Koniec:Select 1\n");
|
||||
}
|
||||
//printf("Koniec:Select 1\n");
|
||||
//Set Clients
|
||||
printf("Rozpoczęcie: Set Clients\n");
|
||||
//printf("Rozpoczęcie: Set Clients\n");
|
||||
for(i =0; i<=4; i++){
|
||||
|
||||
if (client[i].socket > 0) {
|
||||
@ -111,16 +116,16 @@ int main(void) {
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("Koniec: Set Clients\n");
|
||||
printf("Wiadomość:%s\n", msg);
|
||||
//printf("Koniec: Set Clients\n");
|
||||
// printf("Wiadomość:%s\n", msg);
|
||||
//PRZETWARZANIE WIADOMOŚCI
|
||||
printf("Rozpoczecie:Select 2\n");
|
||||
if(select(max_fd+1, NULL, &Clients, NULL, NULL) > 0) {
|
||||
//printf("Rozpoczecie:Select 2\n");
|
||||
if(select(max_fd+1, NULL, &Clients, NULL, &timeout) > 0) {
|
||||
|
||||
for(i=0;i<=4;i++){
|
||||
if (FD_ISSET(client[i].socket, &Clients)) {
|
||||
for(j=0;j<=4;j++) {
|
||||
if(i!=j && client[j].socket!=0) {
|
||||
if(client[j].socket!=0) {
|
||||
send(client[j].socket, msg, 1024, 0);
|
||||
}
|
||||
}
|
||||
@ -128,7 +133,7 @@ int main(void) {
|
||||
}
|
||||
|
||||
}
|
||||
printf("Koniec:Select 2\n");
|
||||
//printf("Koniec:Select 2\n");
|
||||
/*for(i = 0; i<=4; i++)
|
||||
{
|
||||
if(client[i].socket != 0 && FD_ISSET(client[i].socket, &Clients))
|
||||
|
Loading…
Reference in New Issue
Block a user