GitXplorerGitXplorer
h

non-blocking-tcp-server-sample

public
3 stars
1 forks
0 issues

Commits

List of commits on branch master.
Unverified
9b6b4d5abdc87ebfa9a15a9fc1b7021e0711aa55

Update README.md

hharidas committed 10 years ago
Unverified
326bde37832d413ad70aab92ba97af3c50f6c6e5

Format update into the README file.

hharidas committed 10 years ago
Unverified
72f567b65ecb6bcaba7ff452687f221ec39cc8e3

Updtated the README.md file.

hharidas committed 10 years ago
Unverified
4d44ffcd55f1af61ffd132df1b9cfd354d3384e4

Initial commit with sample files.

hharidas committed 10 years ago
Unverified
35df2ae9d0d009a6081d05bb641e580bda0e8de6

Initial commit

hharidas committed 10 years ago

README

The README file for this repository.

non-blocking-tcp-server-sample

Simple Non blocking TCP Server and client to simulate the socket error 104 and 107 at the client side.

For more details about this repo, please read my blog entry -

http://haridas.in/what-happens-when-we-hit-the-speed-limit-of-python.html

How to Run this TCP server and Client

Start the C server. Which listening on the port 8000 and handles the Client connections on another thread.

$ gcc tcp_server.c
$ ./a.out

On another shell environemnt run python client. It has two options -

  1. Run the Python client which gives the error 104 and 107 issue. Which is the issue I'm getting right now on the production machine.

  2. Another implementation of the Python client which fixes the issue and read the socket data without causing socket error 104 and 107

Bellow command will crash after a while since the server closes the socket on its side due to the kernel sending buffer is full on the server side.

$ python tcp_server.py  # Simulate the tcp client with socket problem.

Bellow command will read the socket data in non-blocking mode and read entire data from the socket till it throws EAGAIN exception.

$ python tcp_server.py -c # This client has the option to fix that issue.

This time the client won't throw any excetion and the server and client work smoothly. So finally I got the protype to fix the actual production system.

To See what is happening while running this scripts run tcpdump caommand.

$ sudo tcpdump -i any port 8000