Advertisement
Guest User

new

a guest
Sep 23rd, 2019
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.44 KB | None | 0 0
  1. #client
  2. import socket
  3.  
  4. # 创建 socket 对象
  5. C = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  6. BUFFERSIZE = 1024
  7. # 获取本地主机名
  8. host = socket.gethostname()
  9. # 设置端口号
  10. port = 9999
  11. # 连接服务,指定主机和端口
  12. while True:
  13.     # 接收小于 1024 字节的数据
  14.     msg = input('>>:').strip()
  15.     C.sendto(msg.encode('utf-8'), (host, port))
  16.     msgBack,addr = C.recvfrom(BUFFERSIZE)
  17.     print(msgBack.decode('utf-8'),addr)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement