Updated: 2025-12-28 Sun 19:48

# socketprogramminginc

planted: 2024-12-13 last tended to: 2025-12-28

From: Web Link

## Steps:

The steps involved in establishing a socket on the client side are as follows:

1. Create a socket with the socket() system call
2. Connect the socket to the address of the server using the connect() system call
3. Send and receive data. There are a number of ways to do this, but the simplest is to use the read() and write() system calls.

The steps involved in establishing a socket on the server side are as follows:

1. Create a socket with the socket() system call
2. Bind the socket to an address using the bind() system call. For a server socket on the Internet, an address consists of a port number on the host machine.
3. Listen for connections with the listen() system call
4. Accept a connection with the accept() system call. This call typically blocks until a client connects with the server.
5. Send and receive data

## Socket types:

When you create a socket, you must specify the address domain and the socket type, the client and server can only communicate if they are of the same type and in the same domain.

The two most common address domains:

- unix domain (they share common file system)
- internet domain

The two most common socket types:

- stream sockets (continuous stream of characters) - uses tcp
- datagram sockets (reads the entire messages at once) - uses dp

Backlinks

- cnotes