Skip to Content
Mastering Python for Networking and Security
book

Mastering Python for Networking and Security

by José Manuel Ortega
September 2018
Intermediate to advanced
426 pages
10h 46m
English
Packt Publishing
Content preview from Mastering Python for Networking and Security

Implementing the TCP serverIn this example, we are going to create a multithreaded TCP server.

The server socket opens a TCP socket on localhost:9999 and listens to requests in an infinite loop. When you receive a request from the client socket, it will return a message indicating that a connection has been made from another machine.

The while loop keeps the server program alive and does not allow the code to end. The server.listen(5) statement listens to the connection and waits for the client. This instruction tells the server to start listening with the maximum backlog of connections set to 5.

You can find the following code in the tcp_server.py file inside the tcp_client_server folder:

import socketimport threadingbind_ip = "localhost" ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering Python for Networking and Security - Second Edition

Mastering Python for Networking and Security - Second Edition

José Manuel Ortega
Python for Cybersecurity

Python for Cybersecurity

Howard E. Poston, III

Publisher Resources

ISBN: 9781788992510Supplemental Content