Answers for "python udp server example"

2

python UDP server

####### UDP Server #######

from socket import socket,AF_INET , SOCK_DGRAM

sobj = socket(AF_INET,SOCK_DGRAM)


ip = '127.0.0.1'
port = 20000

sobj.bind((ip,port))

while True:
    msg = sobj.recvfrom(2048)
    print(msg)
    
####### UDP Client #######

from socket import socket,AF_INET , SOCK_DGRAM

sobj = socket(AF_INET,SOCK_DGRAM)


ip = '127.0.0.1'
port = 20000

msg = "Hello World"
sobj.sendto(msg.encode(),(ip,port))
Posted by: Guest on August-25-2021

Python Answers by Framework

Browse Popular Code Answers by Language