PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, October 22, 2022

[FIXED] How to check if localhost python server is running?

 October 22, 2022     gdscript, godot, python, sockets, udp     No comments   

Issue

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?


Solution

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.



Answered By - Theraot
Answer Checked By - Mildred Charles (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing