Question
Please modify the following socket program and let the server send itself (the executable file) to the client. Socket Programming Example ============================================= Socket Server Example
Please modify the following socket program and let the server send itself (the executable file) to the client.
Socket Programming Example
=============================================
Socket Server Example (server.c) ============================================= #include
Discussions:
1) The call to the function socket() creates an UN-named socket inside the kernel and returns an integer known as socket descriptor.
2) This function takes domain/family as its first argument. For Internet family of IPv4 addresses we use AF_INET.
3) The second argument SOCK_STREAM specifies that the transport layer protocol that we want should be reliable ie it should have acknowledgement techniques. For example : TCP
4) The third argument is generally left zero to let the kernel decide the default protocol to use for this
5) The call to the function bind() assigns the details specified in the structure serv_addr to the socket created in the step above. The details include, the family/domain, the interface to listen on(in case the system has multiple interfaces to network) and the port on which the server will wait for the client requests to come.
6) The call to the function listen() with second argument as 10 specifies maximum number of client
7) After the call to listen(), this socket becomes a fully functional listening socket.
8) In the call to accept(), the server is put to sleep and when for an incoming client request, the three way TCP handshake* is complete, the function accept () wakes up and returns the socket descriptor representing the client socket.
9) The call to accept() is run in an infinite loop so that the server is always running and the delay or sleep of 1 sec ensures that this server does not eat up all of your CPU processing.
10) As soon as server gets a request from client, it prepares the date and time and writes on the client socket through the descriptor returned by accept().
============================================= Socket Client Example (client.c)
============================================= #include
============================================= Discussions: 1) A socket is created through call to socket() function.
2) Information like IP address of the remote host and its port is bundled up in a structure and a call to function connect() is made which tries to connect this socket with the socket (IP address and port) of the remote host.
3) Note that here we have not bind our client socket on a particular port as client generally use port assigned by kernel as client can have its socket associated with any port but In case of server it has to be a well known socket, so known servers bind to a specific port like HTTP server runs on port 80
4)Once the sockets are connected, the server sends the data (date+time) on clients socket through clients socket descriptor and client can read it through normal read call on the its socket descriptor.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started