Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Python Network Programming

You're reading from   Python Network Programming Conquer all your networking challenges with the powerful Python language

Arrow left icon
Product type Course
Published in Jan 2019
Publisher Packt
ISBN-13 9781788835466
Length 776 pages
Edition 1st Edition
Languages
Tools
Concepts
Arrow right icon
Authors (4):
Arrow left icon
Dr. M. O. Faruque Sarker Dr. M. O. Faruque Sarker
Author Profile Icon Dr. M. O. Faruque Sarker
Dr. M. O. Faruque Sarker
Eric Chou Eric Chou
Author Profile Icon Eric Chou
Eric Chou
Abhishek Ratan Abhishek Ratan
Author Profile Icon Abhishek Ratan
Abhishek Ratan
Pradeeban Kathiravelu Pradeeban Kathiravelu
Author Profile Icon Pradeeban Kathiravelu
Pradeeban Kathiravelu
Arrow right icon
View More author details
Toc

Table of Contents (30) Chapters Close

Title Page
Copyright
About Packt
Contributors
Preface
1. Fundamental Concepts FREE CHAPTER 2. Python for Network Engineers 3. Continuous Integration for Network Engineers 4. SDN Concepts in Network Automation 5. Low-Level Network Device Interactions 6. APIs and Intent-Driven Networking 7. The Python Automation Framework – Ansible Basics 8. The Python Automation Framework – Beyond Basics 9. AWS Cloud Networking 10. Working with Git 11. Sockets, IPv4, and Simple Client/Server Programming 12. Multiplexing Socket I/O for Better Performance 13. IPv6, Unix Domain Sockets, and Network Interfaces 14. Programming with HTTP for the Internet 15. Email Protocols, FTP, and CGI Programming 16. Programming Across Machine Boundaries 17. Working with Web Services – SOAP, and REST 18. Network Monitoring and Security 19. Network Modeling 20. Authentication, Authorization, and Accounting (AAA) 21. Open and Proprietary Networking Solutions 22. NFV and Orchestration – A Larger Ecosystem 23. Programming the Internet 1. Other Books You May Enjoy Index

Reusing socket addresses


You want to run a socket server always on a specific port even after it is closed intentionally or unexpectedly. This is useful in some cases where your client program always connects to that specific server port. So, you don't need to change the server port.

 

How to do it...

If you run a Python socket server on a specific port and try to rerun it after closing it once, you won't be able to use the same port. It will usually throw an error like the following command:

Traceback (most recent call last):File "11_10_reuse_socket_address.py", 
   line 40, in <module>    reuse_socket_addr()File "11_10_reuse_socket_address.py", 
   line 25, in reuse_socket_addr    srv.bind( ('', local_port) )File "<string>", line 1, in bindsocket.error: [Errno 98] Address 
    already in use

The remedy to this problem is to enable the socket reuse option, SO_REUSEADDR.

After creating a socket object, we can query the state of address reuse, say an old state. Then, we call the setsockopt...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime