From af4a9f8d59c482117813f2994445bcce97708532 Mon Sep 17 00:00:00 2001 From: s449273 Date: Thu, 2 Jan 2020 18:43:57 +0100 Subject: [PATCH] update --- server/sendv2.c | 30 ++++++++++++++++-------------- server/serverv2.c | 11 +++++++---- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/server/sendv2.c b/server/sendv2.c index a3d691d..bb87528 100644 --- a/server/sendv2.c +++ b/server/sendv2.c @@ -12,7 +12,7 @@ int main(int argc, char **argv) { const int port = 7332; - const char ip[512] = "192.168.0.102"; + const char ip[512] = "127.0.0.1"; struct sockaddr_in endpoint; struct dirent **namelist; char buff[512]; @@ -25,6 +25,19 @@ int main(int argc, char **argv) addrlen = sizeof(struct sockaddr_in); ssize_t count = 0; + if ((sdsocket = socket(AF_INET, SOCK_STREAM, 0)) < 0) + { + printf("socket() failed\n"); + return 1; + } + if (connect(sdsocket, (struct sockaddr *)&endpoint, addrlen) < 0) + { + printf("connect() failed\n"); + return 0; + } + else + printf("CONNECTED\n"); + while (1) { start: @@ -43,23 +56,12 @@ int main(int argc, char **argv) goto start; } - if ((sdsocket = socket(AF_INET, SOCK_STREAM, 0)) < 0) - { - printf("socket() failed\n"); - return 1; - } - if (connect(sdsocket, (struct sockaddr *)&endpoint, addrlen) < 0) - { - printf("connect() failed\n"); - return 0; - } - else - printf("CONNECTED\n"); - send(sdsocket, buff, 512, 0); if (strncmp("FTP", buff, 3) == 0) { + bzero(name_file, 512); + ssize_t total = 0; strncpy(name_file, buff + 4, 509); printf("Name of file :%s\n", name_file); diff --git a/server/serverv2.c b/server/serverv2.c index 90a5ff0..4341153 100644 --- a/server/serverv2.c +++ b/server/serverv2.c @@ -41,13 +41,13 @@ int main(int argc, char **argv) while (1) { - start: + while ((sdconnection = accept(sdsocket, (struct sockaddr *)&endpoint, &addrlen)) >= 0) { - + start: printf("CONNECT FROM : %s\n ", inet_ntoa(endpoint.sin_addr)); bzero(buff, 512); @@ -76,8 +76,9 @@ int main(int argc, char **argv) } free(namelist); - if(s = send(sdconnection, names_files, 512, 0) == 512){ - printf("Done Sending\n"); + if (s = send(sdconnection, names_files, 512, 0) == 512) + { + printf("SEND SUCCESS"); goto start; } } @@ -126,6 +127,7 @@ int main(int argc, char **argv) printf("Downloading succes, numer of bytes = %ld\n", total); fclose(file); + goto start; } else if (strncmp("EXIT", buff, 4) == 0) { @@ -171,6 +173,7 @@ int main(int argc, char **argv) printf("Send success, number of bytes: %ld\n", count); fclose(file); + goto start; } else {