风-fmgao

导航

socket-简单实现

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', 8080))


res1 = server.recvfrom(1024)
print('第一次:', res1)

res2 = server.recvfrom(1024)
print('第二次:', res2)

server.close()

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


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

client.sendto(b'hello', ('127.0.0.1', 8080))
client.sendto(b'world', ('127.0.0.1', 8080))

client.close()

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