Code Introduction to Network Programming in Python

, , Comments Off on Code Introduction to Network Programming in Python

This tutorial will give an introduction to sockets in Python and how to use the socket module to build HTTP servers and clients in Python. It will also cover Tornado, a Python networking library which is ideal for long polling, WebSockets, and other applications that require a long-lived connection to each user.

What Are Sockets?

A socket is a link between two applications that can communicate with one another (either locally on a single machine or remotely between two machines in separate locations).

Basically, sockets act as a communication link between two entities, i.e. a server and a client. A server will give out information being requested by a client. For example, when you visited this page, the browser created a socket and connected to the server.

The socket Module

In order to create a socket, you use the socket.socket() function, and the syntax is as simple as:

import socket
s= socket.socket (socket_family, socket_type, protocol=0)

Read full tutorial at code.tutsplus