Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You are to write a client and server program to transfer a file from a sender to a receiver using TCP (the receiver is the

You are to write a client and server program to transfer a file from a sender to a receiver using TCP (the receiver is the server, the sender is the client). You are given a template for the sender and receiver and your task is to write the following two functions.

int recvFile(char *fileName, int portNum, int maxSize, int options);

int sendFile(char *fileName, char *destIpAddr, int destPortNum, int options);

There should be no changes needed to main(). The templates are below for tcpFileSend.c and tcpFileRecv.c. Also, submit a screenshot of program build and program execution.

tcpFileSend.c

#define WIN // WIN for Winsock and BSD for BSD sockets

//----- Include files --------------------------------------------------------- #include  // Needed for printf() #include  // Needed for memcpy() and strcpy() #include  // Needed for exit() #include  // Needed for file i/o constants #include  // Needed for file i/o constants #include  // Needed for open(), close(), and eof() #ifdef WIN #include  // Needed for all Winsock stuff #endif #ifdef BSD #include  // Needed for sockets stuff #include  // Needed for sockets stuff #include  // Needed for sockets stuff #include  // Needed for sockets stuff #include  // Needed for sockets stuff #include  // Needed for sockets stuff #endif //----- Defines --------------------------------------------------------------- #define PORT_NUM 1050 // Arbitrary port number for the server #define SIZE 256 // Buffer size #define RECV_FILE "recvFile.dat" // File name of received file //----- Prototypes ------------------------------------------------------------ int recvFile(char *fileName, int portNum, int maxSize, int options); //===== Main program ========================================================== int main() { int portNum; // Port number to receive on int maxSize; // Maximum allowed size of file int timeOut; // Timeout in seconds int options; // Options int retcode; // Return code // Initialize parameters portNum = PORT_NUM; maxSize = 0; // This parameter is unused in this implementation options = 0; // This parameter is unused in this implementation // Receive the file printf("Starting file transfer... "); retcode = recvFile(RECV_FILE, portNum, maxSize, options); printf("File transfer is complete "); // Return return(0); } //============================================================================= //= Function to receive a file using TCP = //============================================================================= //= Inputs: = //= fileName -- Name of file to create and write = //= portNum --- Port number to listen and receive on = //= maxSize --- Maximum size in bytes for written file (not implemented) = //= options --- Options (not implemented) = //=---------------------------------------------------------------------------= //= Outputs: = //= Returns -1 for fail and 0 for success = //=---------------------------------------------------------------------------= //= Side effects: = //= None known = //=---------------------------------------------------------------------------= //= Bugs: = //=---------------------------------------------------------------------------= int recvFile(char *fileName, int portNum, int maxSize, int options) { } 

tcpFileRecv.c

#define WIN // WIN for Winsock and BSD for BSD sockets //----- Include files --------------------------------------------------------- #include  // Needed for printf() #include  // Needed for memcpy() and strcpy() #include  // Needed for exit() #include  // Needed for file i/o constants #include  // Needed for file i/o constants #include  // Needed for open(), close(), and eof() #ifdef WIN #include  // Needed for all Winsock stuff #endif #ifdef BSD #include  // Needed for sockets stuff #include  // Needed for sockets stuff #include  // Needed for sockets stuff #include  // Needed for sockets stuff #include  // Needed for sockets stuff #include  // Needed for sockets stuff #endif //----- Defines --------------------------------------------------------------- #define PORT_NUM 1050 // Port number used at the server #define SIZE 256 // Buffer size //----- Prototypes ------------------------------------------------------------ int sendFile(char *fileName, char *destIpAddr, int destPortNum, int options); //===== Main program ========================================================== int main(int argc, char *argv[]) { char sendFileName[256]; // Send file name char recv_ipAddr[16]; // Reciver IP address int recv_port; // Receiver port number int options; // Options int retcode; // Return code // Usage and parsing command line arguments if (argc != 4) { printf("usage: 'tcpFileSend sendFile recvIpAddr recvPort' where "); printf(" sendFile is the filename of an existing file to be sent "); printf(" to the receiver, recvIpAddr is the IP address of the "); printf(" receiver, and recvPort is the port number for the "); printf(" receiver where tcpFileRecv is running. "); return(0); } strcpy(sendFileName, argv[1]); strcpy(recv_ipAddr, argv[2]); recv_port = atoi(argv[3]); // Initialize parameters options = 0; // This parameter is unused in this implementation // Send the file printf("Starting file transfer... "); retcode = sendFile(sendFileName, recv_ipAddr, recv_port, options); printf("File transfer is complete "); // Return return(0); } //============================================================================= //= Function to send a file using TCP = //============================================================================= //= Inputs: = //= fileName ----- Name of file to open, read, and send = //= destIpAddr --- IP address or receiver = //= destPortNum -- Port number receiver is listening on = //= options ------ Options (not implemented) = //=---------------------------------------------------------------------------= //= Outputs: = //= Returns -1 for fail and 0 for success = //=---------------------------------------------------------------------------= //= Side effects: = //= None known = //=---------------------------------------------------------------------------= //= Bugs: = //=---------------------------------------------------------------------------= int sendFile(char *fileName, char *destIpAddr, int destPortNum, int options) { } 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning VB.NET Databases

Authors: Thearon Willis

1st Edition

1594864217, 978-1594864216

More Books

Students also viewed these Databases questions

Question

What is a major limitation of KNN?

Answered: 1 week ago