If you are familiar with socket programming, you would be aware that send and recv are usually blocking calls. This means that the code execution will be blocked until they are successfully resolved.
This prevents us from writing TCP servers that can respond to multiple clients. However, there are different ways where we can write our own web server that can handle multiple connections.
Using select system call
The .select() method allows you to check for I/O completion on more than one socket. This enables you to use more than one socket for a port and multiplex connection using the system call.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Another way to handle multiple client connections is to allocate a single thread to each of the clients.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Contrary to popular opinion, IMHO Async is another way of writing multithreaded code. The difference between using threads and async, with threads it is easier to write buggy code. Also, sometimes it is harder to reason. Async makes it relatively easier to write code that can handle concurrent requests.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This is the same as above, except this uses more convenient high level functions as opposed to using lower level socket APIs.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Java Platform 1 . Why is Java so popular? Overall, Java's combination of platform independence, rich ecosystem, community support, robustness, scalability, security, backward compatibility, and versatility contributes to its enduring popularity among developers and organizations Read more…
Every once in a while, we stumble upon a book that profoundly impacts our lives, instigates change, and even redefines our perspectives. Today, I bring you a curated list of 12 transformative books that encompass Read more…
Toxic workplaces are somewhat a taboo to talk about. It is also something very much personable. The same workplace can be toxic for one and energizing for another. There is really no one size fits Read more…
0 Comments