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()

猜你喜欢

转载自www.cnblogs.com/fmgao-technology/p/9189391.html