September 2018
Intermediate to advanced
426 pages
10h 46m
English
The main difference with TCP is that UDP does not control the errors of the packets that are sent. The only difference between a TCP socket and a UDP socket that must specify SOCK_DGRAM instead of SOCK_STREAM when creating the socket object. Use the following code to create the UDP server:
You can find the following code in the udp_server.py file inside the udp_client_server folder:
import socket,sysbuffer=4096host = "127.0.0.1"port = 6789socket_server=socket.socket(socket.AF_INET,socket.SOCK_DGRAM)socket_server.bind((host,port))while True: data,addr = socket_server.recvfrom(buffer) data = data.strip() print "received from: ",addr print "message: ", data try: response = "Hi %s" % sys.platform except Exception,e: ...