发布时间:2019-09-21 11:10:07编辑:auto阅读(1674)
UDPSocketServer:
from socket import *
from time import ctime
BUFFSIZE = 1024
HOST = "127.0.0.1"
PORT = 10055
ADDR = (HOST, PORT)
mySocket = socket(AF_INET, SOCK_DGRAM, 0)
mySocket.bind(ADDR)
while True:
print("waiting for message...\n")
data, addr = mySocket.recvfrom(BUFFSIZE)
data = data.decode()
print("connection from ", data)
if not data:
break
mySocket.sendto(("[%s] %s" % (ctime(), data)).encode(), addr)
mySocket.close()
UDPSocketClient:
from socket import *
BUFFSIZE = 1024
HOST = "127.0.0.1"
PORT = 10055
ADDR = (HOST, PORT)
mySocket = socket(AF_INET, SOCK_DGRAM,0)
while True:
data = input(">: ")
if not data:
break
mySocket.sendto(data.encode(), ADDR)
data, addr = mySocket.recvfrom(BUFFSIZE)
if not data:
break
print(data)
mySocket.close()
上一篇: 2007-3-3第一天CCNA课
下一篇: FusionChart使用3
47837
46379
37264
34722
29306
25964
24893
19943
19534
18014
5785°
6406°
5921°
5957°
7060°
5904°
5936°
6432°
6400°
7772°