Files
org_roam/Notes/20241213005156-socket_programming_in_c.org
Zaine a1da976cc6
All checks were successful
Build Roam Site / build (push) Successful in 29s
perms fix
2026-05-06 15:52:11 +01:00

1.5 KiB
Executable File

socket_programming_in_c

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