1
0

Zaktualizuj 'server/server.c'

This commit is contained in:
Adam Toppmayer 2019-11-05 17:54:11 +00:00
parent 86bc60b23a
commit e6a7ebefc3

View File

@ -8,6 +8,10 @@
//Połączenia z wieloma klientami
void ObsluzPolaczenie(int gn)
{
/*
char Msg[1024];
char Sciezka[1024];
@ -47,7 +51,16 @@ void ObsluzPolaczenie(int gn)
}
//Main Server
/*
struct client_socket
{
int socket;
struct sockaddr_in address;
};
*/
int main(void) {
char bufor[1024]; //wiadomosc
@ -77,6 +90,114 @@ int main(void) {
printf("Wiadomosc od %s: %s\n", inet_ntoa(nadawca.sin_addr), bufor);
close(gniazdo2);
}
/*
struct sockaddr_in adr_bind;
struct sockaddr_in adr_accept;
int socket_bind, socket_accept;
char msg[1024];
pid_t child_id;
int socket_client[5];
socket_client client;
fd_set Clients;
struct sockaddr_in nadawca;
socklen_t dl = sizeof(struct sockaddr_in);
int i;
int j;
for(i = 0; i < 4; i++)
{
clients[i].socket = 0;
}
socket_bind = socket(AF_INET, SOCK_STREAM, 0);
if(socket_bind < 0) {
printf("Error: Socket\n");
return 1;
}
adr_bind.sin_family = AF_INET;
adr_bind.sin_port = htons(44444);
adr_bind.sin_addr.s_addr = INADDR_ANY;
if (bind(socket_bind, (struct sockaddr*) &adr_bind, sizeof(adr_bind)) < 0) { //bind
printf("Error: Bind\n");
return 1;
}
if (listen(socket_bind, 10) < 0) { //listen
printf("Error: Listen\n");
return 1;
}
//printf("Czekam na polaczenie ...\n");
while (1) {
max_fd = 0;
FD_ZERO(Clients);
FD_SET(socket_bind, Clients);
for(i =0; i<4; i++){
if (client[i].socket > 0) {
FD_SET(client[i].socket, Clients);
if(client[i].socket > max_fd) {
max_fd = client[i].socket;
}
}
}
if(select(max_fd+1, &Clients, NULL, NULL, NULL) < 0) {
ERROR
}
if(FD_ISSET(socket_bind, &Clients)) {
for(i=0;i<4;i++){
if (client[i].socket == 0){
client[i].socket = accept(socket_bind, (struct sockaddr*) &adr_bind, &dl));
break;
} else {
printf("Server Pełen");
}
}
}
for(i = 0; i < 4; i++)
{
if(client[i].socket > 0 && FD_ISSET(clients[i].socket, &Clients))
{
recv(clients[i].socket, &msg, 1024, 0);
if (msg == "EXIT") {
} else if (msg == "DOWNLOAD") {
} else if (msg == "SEND"){
} else {
for(j=0;j<4;j++) {
if(i != j && client[j].socket != 0) {
send(client[i].socket, &msg, 1024, 0);
}
}
}
}
}
}
*/
//Połączenie z wieloma Klientami
/*
struct sockaddr_in adr_serv;