From 1ad9939c9d3e272db8175cb3b187cc358fc129b5 Mon Sep 17 00:00:00 2001 From: avinal <185067@nith.ac.in> Date: Wed, 3 Feb 2021 17:02:46 +0530 Subject: [PATCH] client implementation added --- computer_networks/lab/lab2/client.c | 50 +++++++++++++++++++++++++++ computer_networks/lab/lab2/client.txt | 1 + 2 files changed, 51 insertions(+) create mode 100644 computer_networks/lab/lab2/client.c create mode 100644 computer_networks/lab/lab2/client.txt diff --git a/computer_networks/lab/lab2/client.c b/computer_networks/lab/lab2/client.c new file mode 100644 index 0000000..46192de --- /dev/null +++ b/computer_networks/lab/lab2/client.c @@ -0,0 +1,50 @@ +/** + * /mnt/z/my_git/sixth-semester/computer_networks/simulation/scratch/client.c + * @author Avinal Kumar + * @since February 03, 2021 + * + * LAB 2 - Computer Networks + * Client program to send file + */ + +#include +#include +#include +#include +#include +#include + +#define PORT 2047 + +int main() +{ + int sock1; + sock1 = socket(AF_INET, SOCK_STREAM, 0); + struct sockaddr_in serv; + + //struct sockaddr_in client; + memset(&serv, 0, sizeof(serv)); + + serv.sin_port = htons(PORT); + //printf("%x %x\n",PORT,htons(PORT)); + serv.sin_family = AF_INET; + serv.sin_addr.s_addr = inet_addr("127.0.0.1"); + + printf("Client connecting...\n"); + connect(sock1, (struct sockaddr *)&serv, sizeof(serv)); + char buf[50]; + FILE *fp = fopen("client.txt", "r"); + printf("Preparing file...\n"); + while (!feof(fp)) + { + fread(buf, sizeof(char), 50, fp); + write(sock1, buf, 50); + //bzero(buf,sizeof(buf)); + } + write(sock1, "complete", 50); + sleep(2); + printf("File Successfully sent to Server\n"); + sleep(4); + fclose(fp); + return 0; +} \ No newline at end of file diff --git a/computer_networks/lab/lab2/client.txt b/computer_networks/lab/lab2/client.txt new file mode 100644 index 0000000..c6f0c71 --- /dev/null +++ b/computer_networks/lab/lab2/client.txt @@ -0,0 +1 @@ +Data can be transferred between two computers. \ No newline at end of file