poprawki server.c send.c
This commit is contained in:
parent
678b16c5ef
commit
7c4c081c9a
111
server/send.c
111
server/send.c
@ -30,81 +30,52 @@ int main(int argc, char **argv)
|
||||
|
||||
while (1)
|
||||
{
|
||||
printf("wpisz 11 aby nawiazac polaczenie\nwpisz 22 aby moc napisac polecenie\n");
|
||||
scanf("%s", mess);
|
||||
start:
|
||||
printf("Wpisz zapytanie do serwera\n");
|
||||
|
||||
if (strncmp("11", mess, 2) == 0)
|
||||
scanf("%s", buff);
|
||||
|
||||
if (strncmp("CLIENTOFF", buff, 9) == 0)
|
||||
{
|
||||
printf("Realizowany jest connect\n");
|
||||
if ((sdsocket = socket(AF_INET, SOCK_STREAM, 0)) < 0)
|
||||
{
|
||||
printf("socket() nie powiodl sie (failed)\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (connect(sdsocket, (struct sockaddr *)&endpoint, addrlen) < 0)
|
||||
{
|
||||
printf("connect() nie powiodl sie (failed)\n");
|
||||
return 0;
|
||||
}
|
||||
bzero(odbior, 512);
|
||||
recv(sdsocket, odbior, 10, 0);
|
||||
printf("Wiadomosc tresc: %s\n", odbior);
|
||||
close(sdsocket);
|
||||
return 0;
|
||||
}
|
||||
else if (strncmp("22", mess, 2) == 0)
|
||||
else if (strncmp("HELP", buff, 4) == 0)
|
||||
{
|
||||
printf("Wpisz zapytanie do serwera\n");
|
||||
if ((sdsocket = socket(AF_INET, SOCK_STREAM, 0)) < 0)
|
||||
{
|
||||
printf("socket() nie powiodl sie (failed)\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (connect(sdsocket, (struct sockaddr *)&endpoint, addrlen) < 0)
|
||||
{
|
||||
printf("connect() nie powiodl sie (failed)\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
scanf("%s", buff);
|
||||
send(sdsocket, buff, 512, 0);
|
||||
|
||||
close(sdsocket);
|
||||
|
||||
//////////////////////////////////
|
||||
|
||||
if ((sdsocket = socket(AF_INET, SOCK_STREAM, 0)) < 0)
|
||||
{
|
||||
printf("socket() nie powiodl sie (failed)\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (connect(sdsocket, (struct sockaddr *)&endpoint, addrlen) < 0)
|
||||
{
|
||||
printf("connect() nie powiodl sie (failed)\n");
|
||||
return 0;
|
||||
}
|
||||
bzero(odbior, 512);
|
||||
recv(sdsocket, odbior, 512, 0);
|
||||
printf("%s\n", odbior);
|
||||
}else{
|
||||
if ((sdsocket = socket(AF_INET, SOCK_STREAM, 0)) < 0)
|
||||
{
|
||||
printf("socket() nie powiodl sie (failed)\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (connect(sdsocket, (struct sockaddr *)&endpoint, addrlen) < 0)
|
||||
{
|
||||
printf("connect() nie powiodl sie (failed)\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
scanf("%s", buff);
|
||||
send(sdsocket, buff, 512, 0);
|
||||
|
||||
close(sdsocket);
|
||||
printf("COMMAND LIST:\n CLIENTOFF\n EXIT\n GET_ALL_FILES\n");
|
||||
goto start;
|
||||
}
|
||||
|
||||
if ((sdsocket = socket(AF_INET, SOCK_STREAM, 0)) < 0)
|
||||
{
|
||||
printf("socket() nie powiodl sie (failed)\n");
|
||||
return 1;
|
||||
}
|
||||
if (connect(sdsocket, (struct sockaddr *)&endpoint, addrlen) < 0)
|
||||
{
|
||||
printf("connect() nie powiodl sie (failed)\n");
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
printf("CONNECTED\n");
|
||||
|
||||
send(sdsocket, buff, 512, 0);
|
||||
close(sdsocket);
|
||||
|
||||
if ((sdsocket = socket(AF_INET, SOCK_STREAM, 0)) < 0)
|
||||
{
|
||||
printf("socket() nie powiodl sie (failed)\n");
|
||||
return 1;
|
||||
}
|
||||
if (connect(sdsocket, (struct sockaddr *)&endpoint, addrlen) < 0)
|
||||
{
|
||||
printf("connect() nie powiodl sie (failed)\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
bzero(odbior, 512);
|
||||
recv(sdsocket, odbior, 512, 0);
|
||||
printf("%s\n", odbior);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -13,7 +13,7 @@ int main(int argc, char **argv)
|
||||
{
|
||||
const int port = 7332;
|
||||
struct sockaddr_in myaddr, endpoint;
|
||||
int sdsocket, sdconnection, addrlen, sdconnection2, n;
|
||||
int sdsocket, sdconnection, addrlen, sdconnection2, n, rec;
|
||||
char odbior[512];
|
||||
struct dirent **namelist;
|
||||
char name_file[512];
|
||||
@ -38,7 +38,7 @@ int main(int argc, char **argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
while ((sdconnection =
|
||||
/*while ((sdconnection =
|
||||
accept(sdsocket,
|
||||
(struct sockaddr *)&endpoint,
|
||||
&addrlen)) >= 0)
|
||||
@ -48,7 +48,7 @@ int main(int argc, char **argv)
|
||||
|
||||
close(sdconnection);
|
||||
break;
|
||||
}
|
||||
}*/
|
||||
|
||||
while (1)
|
||||
{
|
||||
@ -58,14 +58,24 @@ int main(int argc, char **argv)
|
||||
(struct sockaddr *)&endpoint,
|
||||
&addrlen)) >= 0)
|
||||
{
|
||||
printf("CONNECT FROM : %s\n ", inet_ntoa(endpoint.sin_addr));
|
||||
|
||||
|
||||
|
||||
|
||||
bzero(odbior, 512);
|
||||
recv(sdconnection, odbior, 512, 0);
|
||||
rec = recv(sdconnection, odbior, 512, 0);
|
||||
|
||||
|
||||
close(sdconnection);
|
||||
|
||||
if (strncmp("GET_ALL_FILES", odbior, 13) == 0)
|
||||
{
|
||||
|
||||
printf("Sending list of names files\n");
|
||||
bzero(names_files, 512);
|
||||
bzero(name_file, 512);
|
||||
|
||||
n = scandir(".", &namelist, NULL, alphasort);
|
||||
if (n == -1)
|
||||
{
|
||||
@ -90,21 +100,33 @@ int main(int argc, char **argv)
|
||||
{
|
||||
|
||||
send(sdconnection2, names_files, 512, 0);
|
||||
|
||||
|
||||
|
||||
close(sdconnection2);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (strncmp("EXIT", odbior, 4) == 0)
|
||||
{
|
||||
printf("Server shut down..\n");
|
||||
|
||||
close(sdconnection);
|
||||
close(sdsocket);
|
||||
|
||||
return 0;
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Wrong query\n");
|
||||
printf("Wrong query\n %s nie istnieje\n", odbior);
|
||||
while ((sdconnection2 =
|
||||
accept(sdsocket,
|
||||
(struct sockaddr *)&endpoint,
|
||||
&addrlen)) >= 0)
|
||||
{
|
||||
|
||||
send(sdconnection2, "Wrong query", 512, 0);
|
||||
|
||||
send(sdconnection2, "wrong query", 512, 0);
|
||||
|
||||
close(sdconnection2);
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user