School of Computing and Information Systems
COMP30023: Computer Systems
Practical Week 9 & Week 10 Hints
Copyright By PowCoder代写 加微信 powcoder
1. To convert the message to uppercase:
(a) Identify where the characters are stored.
(b) Loop over the array which stores the characters, and convert each letter to uppercase.
You may want to read the man page for toupper, in
There is no upper(whole_string) in C (at least not in the standard library).
2. To make connection persistent, we want to be able to send and receive (client), and receive and send
(server) multiple messages on one TCP connection. The current code exits after handling one message.
The logical conclusion would be to make some code loop infinitely. But where?
After which call do we get the socket for the connection? What call closes the connection?
Note that sockfd is the welcome (or listen) socket and newsockfd is the connection socket.
3. GOODBYE-CLOSE-TCP is a string, so we can perform string comparison and break the connection.
Also, a return status of 0 on read indicates that the other side of the connection has closed the socket.
1. The port is #define(ed). The address is currently NULL.
They are both specified on the same line.
From the man page:
node specifies either a numerical network address (for IPv4, numbers-and-dots notation as supported by
inet_aton(3); for IPv6, hexadecimal string format as supported by inet_pton(3)), or a network hostname,
whose network addresses are looked up and resolved.
If node is NULL, then the network address will be set to the loopback interface address (INADDR_LOOP-
BACK for IPv4 addresses, IN6ADDR_LOOPBACK_INIT for IPv6 address); this is used by applications
that intend to communicate with peers running on the same host.
2. i == sockfd handles incoming connection requests. The else branch handles messages from clients.
We first read the message from the client. Then, if the read was successful, we enter the nested else
branch (the last else branch near the end of the code). Then, we loop from 0 to the maximum file
descriptor recorded. If the file descriptor j is not the same socket that we received the message from, is
not the welcome socket, and is in the set, then we send the message to that socket. Effectively, this loop
is causing the message to be sent to all other connected sockets.
Your task is to modify the code in this else branch to send the message back to the sender only.
2. Follow similar steps to Practical 9. However, we want to accept infinitely many new connections, rather
than loop over just one connection (which is closed after the response has been sent).
3. TCP is stream-oriented. This means that the message sent by two write() calls can require 1 read(), 2
read(), or perhaps even more read() calls. read() until all the bytes (up to the indicated length) have
been read.
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com