如何检查Localhost Python服务器是否正在运行?
我正在通过Godot和Python之间的插座发送数据:
Godot:
var socket = PacketPeerUDP.new()
socket.set_dest_address("127.0.0.1", 6000)
var data={...}
socket.put_packet(JSON.print(data).to_ascii())
Python Server:
s= socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
s.bind(("127.0.0.1", 6000))
while True:
data = s.recvfrom(1024)
但是,即使是Python Server不运行Godot代码,
也是如此尝试var Err = socket.set_dest_address(“ 127.0.0.1”,6000)
hopin这将打印出错误
但是它总是打印0,无论是否运行Python服务器
,我如何检查服务器是否可用?
I'm sending data via sockets between godot and python like this:
godot:
var socket = PacketPeerUDP.new()
socket.set_dest_address("127.0.0.1", 6000)
var data={...}
socket.put_packet(JSON.print(data).to_ascii())
python server:
s= socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
s.bind(("127.0.0.1", 6000))
while True:
data = s.recvfrom(1024)
but the problem is even when the python server is not running the godot code sends the data instead of giving an error that the server is not available
I even tried var err=socket.set_dest_address("127.0.0.1", 6000)
hopin this would print out the error
but it always prints 0 whether the python server is running or not
so how do I check if the server is available or not?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是我们正在谈论的UDP。因此,实际上没有建立会话或连接。另外,实际上没有一个公认的软件包。因此,最后唯一的解决方案是在其上实现您自己的可靠性协议(例如,服务器响应,客户等待响应)。尝试在Gamedev网站上搜索DOR UDP可靠性。
set_dest_address
的返回值是err_cant_resolve
(IP无效)或ok ok
。返回
put_packet的值
。它可以返回err_busy
(发送缓冲区已满),失败
(其他使用中的套接字)或ok ok
。This is UDP we are talking about. So there isn't really a session or connection established. Also there isn't really an acknowledged package. So at the end the only solution is to implement your own reliability protocol on top of it (e.g. have the server respond and the client wait for the response). Try searching dor UDP reliability on the gamedev site.
The return values for
set_dest_address
areERR_CANT_RESOLVE
(the IP is not valid) orOK
.The returns values of
put_packet
. It can returnERR_BUSY
(send buffers are full),FAILED
(the socket is otherwise in use) orOK
.