Starting from:

$29.99

INTERNET TECHNOLOGIES LAB Assignment – 1

INTERNET TECHNOLOGIES LAB
Assignment – 1
1. Write a client program (called myclient), and a server program (called myserver) . The client
sends the server a one-byte message that contains either the command "0" or the command "1".
On receiving message "0", the server executes the "date" command on Linux and returns the
result. On receiving the message "1", the server executes the "whoami" command, and returns
the result. The server terminates after executing the command, and the client terminates after
printing the result on the screen.
You need to use sockets to establish the TCP connection first. The client takes three
arguments: the name of the server machine, the port number to which it should connect, and
the command. It first translates from the servers name to its IP address, using the gethostbyname
system call. It uses the IP address to fill in a sockaddr_in structure, then opens a socket to the
server using the socket and connect system calls. Next, it sends the command as a 1-byte
ASCII string, using the write system call. Finally, it reads the reply, using the read call in a loop,
and displays the result on the screen using the write system call.
The server takes one argument, which is the port number on which it listens for an incoming
command. It fills in a sockaddr_in structure with the port number. It uses the socket, bind, and
listen system calls to create a socket, bind the port number to it, and to listen for a request. On
getting the request, it accepts it, reads the message sent to it, executes the corresponding
command using the Unix system system call and writes the result to a temporary file. It then
opens the file for reading, reads the result, and uses the write call to write the results back to the
client.
TCP/IP does not provide message boundaries. So, the client does not know how long a result to
read from the server. Provide a solution to handle this.

More products