March 2019
Beginner
490 pages
12h 40m
English
When working with UDP, the only difference if we compare this to working with TCP in Python is that when creating the socket, you have to use SOCK_DGRAM instead of SOCK_STREAM. Use the following code to create the UDP server. You can find the following code in the udp_server.py file inside the udp folder:
#!/usr/bin/env python3import socket,sysUDP_IP_ADDRESS = "127.0.0.1"UDP_PORT = 12345buffer=4096socket_server=socket.socket(socket.AF_INET,socket.SOCK_DGRAM) #UDPsocket_server.bind((UDP_IP_ADDRESS,UDP_PORT))while True: print("Waiting for client...") data,address = socket_server.recvfrom(buffer) data = data.strip() print("Data Received from address: ",address) print("message: ", data) try: response = "Hi %s" % sys.platform ...Read now
Unlock full access