Learning Python Network Programming

(Sean Pound) #1

Programming with Sockets


After you have interacted with various clients/servers in Python, you will be keen to
create your own custom clients and servers for any protocol of your choice. Python
provides a good coverage on the low-level networking interface. It all starts with
BSD socket interface. As you can assume, Python has a socket module that gives
you the necessary functionality to work with the socket Interface. If you have ever
done socket programming in any other language like C/C++, you will love the
Python socket module.


In this chapter, we will explore the socket module by creating a diverse range of
Python scripts.


The following are the highlights of this chapter:



  • Basics of sockets

  • Working with TCP sockets

  • Working with UDP sockets

  • TCP port forwarding

  • Non-blocking socket I/O

  • Securing sockets with SSL/TLS

  • Creating custom SSL client/server


Basics of sockets


Network programming in any programming language can begin with sockets. But
what is a socket? Simply put, a network socket is a virtual end point where entities
can perform inter-process communication. For example, one process sitting in a
computer, exchanges data with another process sitting on the same or another
computer. We typically label the first process which initiates the communication
as the client and the latter one as the server.

Free download pdf