In my previous post "Introducing Sockets," you saw the functions read(2) and write(2) being used when reading from and writing to sockets. While it was not pointed out at the time, the socketpair(2) function call shown created a pair of sockets using a connection-oriented protocol. Consequently, it was possible to use the familiar read(2) and write(2) functions to perform I/O on those sockets.
When sending and receiving datagrams, however, a different pair of functions is required. This is because each message being sent is potentially sent to a different destination address. The function used for sending a datagram must allow you to specify the address of the intended recipient.
Likewise, when you receive a datagram, you need to find out whom it came from. This new function must provide you with a convenient way to determine the address of the sender.
No comments:
Post a Comment