master
jakeallen 8 months ago
commit 472a47535d

8
.idea/.gitignore vendored

@ -0,0 +1,8 @@
# 默认忽略的文件
/shelf/
/workspace.xml
# 基于编辑器的 HTTP 客户端请求
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Black">
<option name="sdkName" value="Python 3.9" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9" project-jdk-type="Python SDK" />
</project>

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/UDP_test.iml" filepath="$PROJECT_DIR$/.idea/UDP_test.iml" />
</modules>
</component>
</project>

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

@ -0,0 +1,23 @@
# 相当于天线默认目标地址为192.168.49.160,端口号为 8080
import socket
# 1.创建udp对象
sk = socket.socket(type=socket.SOCK_DGRAM)
# 2.在网络中注册该主机(绑定ip和端口号)
sk.bind( ("127.0.0.1",9000) )
while True:
# 3.收发数据的逻辑
"""udp协议下,默认第一次只能接收数据(没有三次握手,不清楚对方的ip和端口号)"""
# 接受数据
msg, addr = sk.recvfrom(1024)
print(msg.decode())
print(addr)
send_data = input("请输入要发送的数据:")
# 发送数据
sk.sendto(send_data.encode(), addr)
# 4.关闭连接
sk.close()

@ -0,0 +1,22 @@
# 接收机相当于本机192.168.49.10,端口号为 5010
import socket
import time
while True:
# 1.创建udp对象
sk = socket.socket(type=socket.SOCK_DGRAM)
# 2.收发数据的逻辑
# 发送数据
msg = input("请输入要发送的数据:")
# sendto( 二进制字节流 , ip端口号 )
sk.sendto(msg.encode(), ("127.0.0.1", 9000))
# 接受数据
msg, addr = sk.recvfrom(1024)
print(msg.decode())
print(addr)
time.sleep(1)
# 3.关闭连接
sk.close()
Loading…
Cancel
Save