一、服务端(Server.py)
服务端要做的事情是:
1. 创建一个Socket对象
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
–>import socket
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
–>s.bind((“”, 8081))
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
–>while True:
# Receive up to 1,024 bytes in a dat本文来源gaodai#ma#com搞*代#码9网#agram
data, addr = s.recvfrom(1024)
print “Received:“, data, “from“, addr
客户端要做的事情是:
1. 创建一个Socket对象。
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
–>import socket
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
–>port = 8081
host = “localhost“
while True:
msg = raw_input()
s.sendto(msg, (host, port))