Skip to content

Commit

Permalink
udp-multi-threading-resources
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhishats7 committed Aug 7, 2024
1 parent 8370573 commit 7d9536c
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 1 deletion.
3 changes: 3 additions & 0 deletions docs/.vitepress/config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ export default defineConfig({
link: '/guides/resources/blocking-and-non-blocking-sockets',
},
{ text: 'HTTP', link: '/guides/resources/http' },
{ text: 'UDP', link: '/guides/resources/udp' },
{ text: 'Multi-threading', link: '/guides/resources/multi-threading' },

// { text: 'Internet Protocol (IP)', link: '/guides/resources/ip' },
// { text: 'File descriptors', link: '/guides/resources/file-descriptors' },

Expand Down
Binary file added docs/assets/resources/multi-threading.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/resources/udp-ip-packet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions docs/guides/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ The guides feature supplementary documentation intended for your reference as yo
-[Linux epoll](/guides/resources/introduction-to-linux-epoll)
- [Blocking & Non-Blocking Sockets](/guides/resources/blocking-and-non-blocking-sockets)
- 🟡 [HTTP](/guides/resources/http)
- 🟡 [UDP](/guides/resources/udp)
- 🟡 [Multi-threading](/guides/resources/multi-threading)

## References

Expand Down
15 changes: 15 additions & 0 deletions docs/guides/resources/multi-threading.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# MULTI-THREADING

Thread is the smallest unit of execution within a process. Threads within the same process share memory and resources, facilitating communication and data sharing. Multi-threading is the ability of a program or an operating system to enable more than one user at a time without requiring multiple copies of the program running on the computer.

Creating a thread is less expensive than creating a new process because the newly created thread uses the current process address space.

**Concurrency**: Multiple threads are making progress at the same time. This is more about dealing with multiple tasks at once rather than running them simultaneously.

**Non-blocking Operations**: Threads enable non-blocking I/O operations, where one thread can handle input/output operations while other threads continue executing without waiting.

**Faster Response Times**: With the ability to process multiple requests concurrently, client requests can be handled more quickly, reducing the time each client waits for a response.

**Handling High Loads**: Concurrent servers can scale to handle a large number of simultaneous connections, making them suitable for high-traffic applications like web servers, email servers, and database servers.

![multi-threading.png](/assets/resources/multi-threading.png)
2 changes: 1 addition & 1 deletion docs/guides/resources/sockets.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Sockets are the interface to use the [TCP protocol](https://en.wikipedia.org/wik

![socket.png](/assets/phase-0-overview/socket.png)

Sockets in networking are typically classified into two types:
The main two types of sockets in networking:

- `SOCK_STREAM`: Stream sockets ensure that data is delivered in the order it was sent and without errors. For example web browsing ([HTTP](https://en.wikipedia.org/wiki/HTTP)), email ([STMP](https://en.wikipedia.org/wiki/Simple_Mail_Transfer_Protocol)), etc use this socket type ([TCP](https://en.wikipedia.org/wiki/Transmission_Control_Protocol)).
- `SOCK_DGRAM`: Datagram sockets send packets of data, called datagrams, without establishing a connection or ensuring delivery. For example video streaming, online gaming etc. use this socket type ([UDP](https://en.wikipedia.org/wiki/User_Datagram_Protocol)).
Expand Down
20 changes: 20 additions & 0 deletions docs/guides/resources/udp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# UDP

**User Datagram Protocol (UDP)** is part of the Transport Layer of the TCP/IP suite. UDP provides a connectionless communication method for sending data between devices. Unlike TCP, UDP does not guarantee data delivery, ordering, or error recovery. Instead, it offers a simpler, faster way to transmit data with minimal overhead.

When sending data over the network from the Application layer, we create a UDP socket. To send and receive data using this socket, we use the socket programming APIs provided by the operating system. These APIs include system calls like `sendto()` and `recvfrom()`, which facilitate the transmission of data between the Application layer and the Transport layer.

![udp-ip-packet.png](/assets/resources/udp-ip-packet.png)

Here’s how UDP handles data:
1. **Socket Creation:**
- **UDP Socket:** An application creates a UDP socket using the `socket()` system call, specifying the UDP protocol.
2. **Data Transmission:**
- **Sending Data:** When data is sent via a UDP socket, the data is provided to the `sendto()` system call. The data is then encapsulated in UDP packets (datagrams).
- **Receiving Data:** The `recvfrom()` system call is used to receive data from the socket. The received UDP datagram is then passed up to the application layer.
3. **UDP Datagram Structure:**
- **Datagram Format:** A UDP datagram consists of a UDP header and the data payload. The UDP header includes fields such as:
- **Source Port:** The port number of the sending application.
- **Destination Port:** The port number of the receiving application.
- **Length:** The length of the UDP header and payload.
- **Checksum:** Used for error checking, but it's optional in IPv4.

0 comments on commit 7d9536c

Please sign in to comment.