Home > Blockchain >  How to check if localhost python server is running?
How to check if localhost python server is running?

Time:07-02

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?

CodePudding user response:

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.

  • Related