美文网首页
python socket

python socket

作者: 基本密码宋 | 来源:发表于2018-01-05 16:43 被阅读9次

发送方

#coding:utf-8


from socket import *

 

updSocket = socket(AF_INET,SOCK_DGRAM)

 
updSocket.sendto("hahhaha".encode('utf-8'),("192.168.4.7",7777))

接收方

#coding:utf-8

from socket import *

#接受方  必須綁定端口

updSocket = socket(AF_INET,SOCK_DGRAM)

updSocket.bind(("192.168.4.16",7777)) #绑定端口      

data= updSocket.recvfrom(1024)   #就收其他地方的数据

print(data)

updSocket.close()

相关文章

网友评论

      本文标题:python socket

      本文链接:https://www.haomeiwen.com/subject/pcesnxtx.html