This post contains a brief about how sockets are implemented in python. This is OS specific hence I will only be covering for UNIX based systems. Windows based systems I would urge to avoid due to the gory details. The main module is located in the file Modules/socketmodule.h. Observe how the appropriate files are included into the system depending on the operating system.

typedef struct {
PyObject_HEAD
SOCKET_T sock_fd; /* Socket file descriptor */
int sock_family; /* Address family, e.g., AF_INET */
int sock_type; /* Socket type, e.g., SOCK_STREAM */
int sock_proto; /* Protocol type, usually 0 */
PyObject *(*errorhandler)(void); /* Error handler; checks
errno, returns NULL and
sets a Python exception */
double sock_timeout; /* Operation timeout in seconds;
0.0 means non-blocking */
PyObject *weakreflist;
} PySocketSockObject;

Is the main socket object. Insert a breakpoint in the file Modules/socketmodule.c on line number 806. Create a program to create sockets and observe how the sockets operate.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s