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 UDP client

To begin implementing the client, we will need to declare the IP address that we will be trying to send our UDP messages to, as well as the port number. This port number is arbitrary but you must ensure you aren't using a socket that has already been taken:

UDP_IP_ADDRESS = "127.0.0.1" UDP_PORT = 6789 message = "Hello, Server"

Now it's time to create the socket through which we will be sending our UDP message to the server:

clientSocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

And finally, once we've constructed our new socket, it's time to write the code that will send our UDP message:

clientSocket.sendto(Message, (UDP_IP_ADDRESS, UDP_PORT))

You can find the following code in the udp_client.py

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