Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #client
- import socket
- # 创建 socket 对象
- C = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
- BUFFERSIZE = 1024
- # 获取本地主机名
- host = socket.gethostname()
- # 设置端口号
- port = 9999
- # 连接服务,指定主机和端口
- while True:
- # 接收小于 1024 字节的数据
- msg = input('>>:').strip()
- C.sendto(msg.encode('utf-8'), (host, port))
- msgBack,addr = C.recvfrom(BUFFERSIZE)
- print(msgBack.decode('utf-8'),addr)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement