程序代写代做代考 Client/Server Model

Client/Server Model

Test 1
Test date: Week 9 [Nov. 1, Tuesday]
Test venue: C408
Test time: 14:00-17:30
Test content: Ch 1 to Ch 3
Exam-style: Finish 3 programming problems:
Problem 1: 20 points
Problem 2: 40 points
Problem 3: 40 points

Name/class: Stud_no:

Problem 1: 20 %
Problem 2: 40%
Problem 3: 40%

Notes
You cannot pass the course if you miss or take away the test paper!

Please look up ~Handbook\Beej’s Guide to Network Programming.pdf for solving the problems you encounter, say the usage of socket functions.

Hints for typical errors:
Error: dereferencing(废弃) pointer to incomplete type
Possible reasons: (1) struct name is wrong
(2) header files are missing

Problem 1.2
(10 pt) Print your local machine name using gethostbyaddr()
Run in command line like: ./your_progrm IP_addr
Hints in next page

Hints for Problem 1.2
struct hostent * gethostbyaddr ( const char * addr, int len, int type)
Parameters:
addr [in] A pointer to an address in network byte order.
len [in] The length of the address.
type [in] The type of the address.
struct hostent {
char * h_name;
char * * h_aliases;
short h_addrtype;
short h_length;
char * * h_addr_list;
};

inet_addr(): convert IP_addr in the dotted-quad notation to the binary data in network byte order

Problem 3
Revise(修正) TCPEchoServer.c so as to run server as follows:
./server port_num
We require that server can handle three cases below:
(10 pt) If server finds that the local server administrator inputs “quit”, the server exits, otherwise, server executes(执行) Things 1 and 2 presented below, repeatedly.(反复的)
(15 pt) Thing 1: If server finds that the local server administrator(管理员) inputs a piece of information through keyboard, server prints the same message, where a piece of information is ended when the user keys “RETURN”

Problem 3 (cont.)
(15 pt) Thing 2: If server receives a client_message from client, server and client print a complete client_message in the inverse order.
For example, if client_message=“AABBCCDD”, server should send back and print such a message: “DDCCBBAA”, rather than two messages: “BBAA” and “DDCC”. Also, client prints the complete message: “DDCCBBAA” coming from the server.
Hint 1: how to ensure that the message is “DDCCBBAA”? Explain your method and implement it.
Hint 2: You need to revise TCPEchoClient.c as well.