1
0
Fork 0

Zaktualizuj 'server/server.c'

This commit is contained in:
Adam Toppmayer 2019-11-05 19:48:03 +00:00
parent e6a7ebefc3
commit b3e7938dc4
1 changed files with 3 additions and 131 deletions

View File

@ -5,52 +5,7 @@
#include <string.h>
#include <arpa/inet.h>
#include <unistd.h>
//Połączenia z wieloma klientami
void ObsluzPolaczenie(int gn)
{
/*
char Msg[1024];
char Sciezka[1024];
while (1) {
//recv() <- czeka na wiadomość
FD_ZERO(&readfds);
FD_SET(gniazdoTCP, &readfds);
timeout.tv_sec = 1;
timeout.tv_usec = 0;
gniazdo_src = socket();
int gniazdo_kli;
if (select(gniazdo+1, &readfds, NULL, NULL, &timeout) > 0)
{
gniazdo_kli = accept(gniazdo_src, (struct sockaddr*) adres, &dladr);
}
memset(Msg, 0, 1024);
recv(Gniazdo_Klient, Msg, 1024, 0);
//Porównywanie wiadomości
If (Msg == "wyślij") {
} else (Msg = "pobierz") {
} else (Msg == "exit") {
close(Gniazdo_Klient);
close(Gniazdo_Server);
} else {
//wyślij do wszystkich wiadomość
//(opconalne)nadpisz plik z historią rozmów - plik tekstowy
for(each gniazdo in readfs [select]){
send(gniazdo,wiadomość, );
}
}
}
*/
}
//Main Server
/*
struct client_socket
@ -172,9 +127,9 @@ int main(void) {
if (msg == "EXIT") {
} else if (msg == "DOWNLOAD") {
//fork, który dostanie adres i plik i będzie zajmował się wysyłaniem
} else if (msg == "SEND"){
//fork, który dostanie adres i plik i będzie zajmował się wysyłaniem
} else {
for(j=0;j<4;j++) {
if(i != j && client[j].socket != 0) {
@ -189,90 +144,7 @@ int main(void) {
}
*/
//Połączenie z wieloma Klientami
/*
struct sockaddr_in adr_serv;
int gt, port;
printf("Numer portu: ");
scanf("%d", &port);
gt = socket(PF_INET, SOCK_STREAM, 0);
adr_serv.sin_family = AF_INET;
adr_serv.sin_port = htons(port);
adr_serv.sin_addr.s_addr = INADDR_ANY;
if (bind(gt,(struct sockaddr*) &adr_serv,
sizeof(struct sockaddr_in)) < 0)
{
printf("Bind nie powiodl sie.\n");
return 1;
}
if (listen(gt, 10) < 0)
{
printf("Listen nie powiodl sie.\n");
return 1;
}
ObsluzObaProtokoly(gt, &adr_serv);
fd_set readfds;
struct timeval timeout;
unsigned long proba;
proba = 0;
while(1)
{
FD_ZERO(&readfds);
FD_SET(gniazdoTCP, &readfds);
timeout.tv_sec = 1;
timeout.tv_usec = 0;
if (select(gniazdoTCP+1, &readfds, NULL, NULL, &timeout) > 0)
{
proba = 0;
if (FD_ISSET(gniazdoTCP, &readfds))
ObsluzTCP(gniazdoTCP, adres);
int nowe_gniazdo;
char bufor[1024];
socklen_t dladr = sizeof(struct sockaddr_in);
nowe_gniazdo =
accept(gniazdo, (struct sockaddr*) adres,
&dladr);
if (nowe_gniazdo < 0)
{
printf("Bledne polaczenie (accept < 0)\n");
return;
}
memset(bufor, 0, 1024);
while (recv(nowe_gniazdo, bufor, 1024, 0) <= 0);
DrukujNadawce(adres);
printf("[TCP]: %s\n", bufor);
close(nowe_gniazdo);
}
else
{
proba++;
printf("Czekam %lu sekund i nic ...\n", proba);
}
}
return 0;
*/
//Polączenie z wieloma klientami
close(gniazdo);
return 0;
}