File Transfer Using TCP
File Transfer Using TCP
Assignment 3
printf("\n");
return 0;
}
Client:
#include<stdio.h>
#include<string.h>
#include<sys/types.h>
#include<sys/socket.h>
#include<netinet/in.h>
#include<arpa/inet.h>
#include<unistd.h>
int main(int argc,char *argv[])
{
int sockfd,new_fd;
struct sockaddr_in server_addr,client_addr;
char str[1024];
sockfd=socket(AF_INET,SOCK_STREAM,0);
if(sockfd<0)
{
printf("\nSocket not created");
return -1;
}
printf("\nSuccesful socket created");
bzero(&server_addr,sizeof(server_addr));
server_addr.sin_family=AF_INET;
server_addr.sin_addr.s_addr=inet_addr("127.0.0.1");
server_addr.sin_port=htons(8081);
connect(sockfd,(struct sockaddr *)&server_addr,sizeof(server_addr));
printf("\nSuccesfully connected to the server!!");
Sample Input/Output:
Result:
The requested file from the client was successfully transferred by the server
and a new file with the same contents was created successfully.