python class udp 1

python class udp

1 import socket
   2 
   3 UDP_IP = "127.0.0.1"
   4 UDP_PORT = 5005
   5 MESSAGE = b"Hello, World!"
   6 
   7 print("UDP target IP: %s" % UDP_IP)
   8 print("UDP target port: %s" % UDP_PORT)
   9 print("message: %s" % MESSAGE)
  10 
  11 sock = socket.socket(socket.AF_INET, # Internet
  12                      socket.SOCK_DGRAM) # UDP
  13 sock.sendto(MESSAGE, (UDP_IP, UDP_PORT))

Here is what the above code is Doing:
1. We import the socket library.
2. We define the IP address and port number of the server.
3. We define the message we want to send.
4. We print the IP address and port number of the server.
5. We print the message we want to send.
6. We create a socket object.
7. We send the message to the server.

Similar Posts