首页 > 代码库 > python_socket

python_socket

# socket_server.pyimport sockets = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)s.bind((‘‘,8089))while True:# Receive up to 1,024 bytes in a datagramdata, addr = s.recvfrom(1024)print "Received:", data, "from", addr

 

# socket_client.pyimport sockets = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)port = 8089host = "localhost"while True:msg = raw_input(Enter message:)s.sendto(msg, (host, port))

 

python_socket