advanced system programming-socket
This project is to be done either by one student or by pairs (two students)
Write two programs (in C or in Java), a client and a server, to implement a simple remote shell connection. The server process and the client process will run on two different machines and the communication between the two processes is achieved using Sockets. The server task can be summarized as follows :
-
The server must start running before any client, and wait for connections.
-
When the server gets a client, it forks and let the child process take care of the client in a separate function, called serviceClient, while the parent process goes back to wait for the next client.
-
Then, the server’s child process
- uses " dup2()" to make the screen descriptor designate the client socket
- gets in an infinite loop then :
- reads a shell command from the client’s socket,
- if the client sends "quit", then the server’s child, closes socket and quits.
- otherwise, it excutes command, using the " system()" library function,
-
The client process connects to the server, then
- gets into an infinite loops
- reads a command from keyboard,
- write the command to the server,
- if command is "quit", closes socket and quits
- otherwise, reads command output from socket and displays them on the screen
- gets into an infinite loops
-
Found out the ip address of server
- use "ip a" command to see the ipv4 address
-
Start the server first
ps: format is: ./server.exe 5000
5000 is the port -
Then start the client
ps: format is: ./client.exe [ip address] [port]
STEPs
- Input a shell command in the client.
- The command will be sent to the server.
- Server will read the shell command from the client.
- Server will excute the command, and show the result in the client.
CLOSE THE PROJECT