O'Reilly logo

Advanced Mac OS X Programming: The Big Nerd Ranch Guide by Mark Dalrymple

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Client Coding

Code on the client is very similar to the server:

  1. Figure out the address information of the server.

  2. Construct a struct sockaddr_in address.

  3. Get a socket().

  4. connect() to the server.

  5. Use read() and write() to send and receive data.

connect

connect() makes the connection to the server. It returns a file descriptor that you read and write with.

int connect (int socket, const struct sockaddr *address, socklen_t addresslen);

Give it the address to connect to, and it returns zero if the connection succeeds or -1 for an error, with errno set.

Example 14.4 is a client that is a little more convenient than telnet. It follows telnet’s example in searching for the host address: first it does an IPv6 lookup and tries all addresses listed ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required