2019-11-25 12:54:10 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <netdb.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
char odbior[10];
|
|
|
|
struct sockaddr_in endpoint;
|
|
|
|
int sdsocket, addrlen, sdconnection;
|
|
|
|
const int port = 7332;
|
|
|
|
const char ip[512] = "192.168.0.43";
|
|
|
|
char buff[512];
|
|
|
|
char eee[1];
|
|
|
|
struct dirent **namelist;
|
|
|
|
int n;
|
|
|
|
char wiadomosc[512];
|
|
|
|
char mess[512];
|
|
|
|
|
|
|
|
endpoint.sin_family = AF_INET;
|
|
|
|
endpoint.sin_port = htons(port);
|
|
|
|
endpoint.sin_addr.s_addr = inet_addr(ip);
|
|
|
|
addrlen = sizeof(struct sockaddr_in);
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
2019-11-27 14:21:20 +01:00
|
|
|
start:
|
|
|
|
printf("Wpisz zapytanie do serwera\n");
|
2019-11-25 12:54:10 +01:00
|
|
|
|
2019-11-27 14:21:20 +01:00
|
|
|
scanf("%s", buff);
|
2019-11-25 12:54:10 +01:00
|
|
|
|
2019-11-27 14:21:20 +01:00
|
|
|
if (strncmp("CLIENTOFF", buff, 9) == 0)
|
2019-11-25 12:54:10 +01:00
|
|
|
{
|
|
|
|
close(sdsocket);
|
2019-11-27 14:21:20 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else if (strncmp("HELP", buff, 4) == 0)
|
|
|
|
{
|
|
|
|
printf("COMMAND LIST:\n CLIENTOFF\n EXIT\n GET_ALL_FILES\n");
|
|
|
|
goto start;
|
|
|
|
}
|
2019-11-25 12:54:10 +01:00
|
|
|
|
2019-11-27 14:21:20 +01:00
|
|
|
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");
|
2019-11-25 12:54:10 +01:00
|
|
|
|
2019-11-27 14:21:20 +01:00
|
|
|
send(sdsocket, buff, 512, 0);
|
|
|
|
close(sdsocket);
|
2019-11-25 12:54:10 +01:00
|
|
|
|
2019-11-27 14:21:20 +01:00
|
|
|
if ((sdsocket = socket(AF_INET, SOCK_STREAM, 0)) < 0)
|
|
|
|
{
|
|
|
|
printf("socket() nie powiodl sie (failed)\n");
|
|
|
|
return 1;
|
2019-11-25 12:54:10 +01:00
|
|
|
}
|
2019-11-27 14:21:20 +01:00
|
|
|
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);
|
2019-11-25 12:54:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|