问题描述
我在 python 中设置了简单的服务器/客户端,并通过端口号为 1234 的 UDP 协议在它们之间来回发送信息。但是,这些数据包不会在 Wireshark 中捕获。 有人可以帮我过滤吗? 我的服务器代码:
import socket
#CONfigURATION OF THE SERVERPORT
serverPort=1234
#CONfigURATION OF THE SERVERSOCKET
serverSocket=socket.socket(socket.AF_INET,socket.soCK_DGRAM)
#GENErating THE ARTIFICIAL SERVER
serverSocket.bind((socket.gethostname(),serverPort))
print("server is ready to receive")
#sending the server into listening mode
while 1:
#server is gettinbg the client info
#plus we also get the address
msgandaddress=serverSocket.recvfrom(1024)
#server is reading the text
a=(msgandaddress[0].decode())
#server is sending the response
filecomposition="response sent for "+str(a)
#server is sending the composition to the client
serverSocket.sendto(filecomposition.encode(),msgandaddress[1])
我的客户代码
import socket
from datetime import datetime
import time
#configuring the server port
serverPort=1234
#configuring the socket to UDP
clientsocket=socket.socket(socket.AF_INET,socket.soCK_DGRAM)
print(socket.gethostname())
for i in range(0,1):
#marking the starttime
starttime=datetime.Now()
#sending the message at the specific time
clientsocket.sendto(str(i).encode(),(socket.gethostname(),serverPort))
print("ping has been sent at "+str(starttime))
#receiving the message at the specific time
responseandaddress=clientsocket.recvfrom(1024)
endttime=datetime.Now()
print("pong has been received at "+str(endttime))
#calculating the difference
print(str(i)+"."+" RTT TIME:"+str((endttime-starttime).total_seconds()))
print("\n\n")
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)