风-fmgao

导航

socket_udp客户端循环输入

server--------------
#!/usr/bin/env python
# encoding: utf-8  
# Date: 2018/6/7


from socket import *

server = socket(AF_INET, SOCK_DGRAM)
server.bind(('127.0.0.1', 8808))

while True:
    data, client_addr = server.recvfrom(1024)
    print(data)

    server.sendto(data.upper(), client_addr)

server.close()

client----------------

#!/usr/bin/env python
# encoding: utf-8  
# Date: 2018/6/7


from socket import *
client = socket(AF_INET, SOCK_DGRAM)

while True:
    msg = input('>>>:').strip()
    client.sendto(msg.encode('utf-8'), ('127.0.0.1', 8808))

    data, server_addr = client.recvfrom(1024)
    print(data, server_addr)

client.close()


posted on 2018-06-15 23:55  风-fmgao  阅读(140)  评论(0编辑  收藏  举报