如何检查Localhost Python服务器是否正在运行?

发布于 2025-02-12 18:37:47 字数 581 浏览 1 评论 0原文

我正在通过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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

复古式 2025-02-19 18:37:47

这是我们正在谈论的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 are ERR_CANT_RESOLVE (the IP is not valid) or OK.

The returns values of put_packet. It can return ERR_BUSY (send buffers are full), FAILED (the socket is otherwise in use) or OK.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文