0 votes

I want to make a multiplayer board game, I have a python server and the godot client, and somewhy the python server doesn't notice the client trying to connect.

They python script never prints the "added connection..." and the client side never enters the connectionestablished signal and after a while it is closing with wasclean being false.

I tried changing the ip I connect to and it works

Client side:

var _client = WebSocketClient.new()
export var websocket_url = ""

func _ready():
    _client.connect("connection_closed", self, "_closed")
    _client.connect("connection_error", self, "_closed")
    _client.connect("connection_established", self, "_connected")
    _client.connect("data_received", self, "_on_data")
    if _client.connect_to_url(websocket_url) != OK:
        print("Unable to connect")

func _closed(was_clean = false):
    print("Closed, clean: ", was_clean)

func _connected(proto = ""):
    main_board = preload("res://Prefabs/Board.tscn").instance()
    main_board.name = 'Board'
    main_board.scale = BOARD_SCALE

    enemy_board = preload("res://Prefabs/Board.tscn").instance()
    enemy_board.name = 'EnemeyBoard'
    enemy_board.scale = Vector2(1,1) - BOARD_SCALE
    enemy_board.position = Vector2(BOARD_SCALE.x * 64 * 6,0)

Server side:

server_socket = socket()
server_socket.bind(('', 80))

game_lobby = []

while True:
    rlist, wlist, xlist = select([server_socket] + game_lobby, [], [])
    for current_socket in rlist:
        if current_socket == server_socket:
            (new_socket, address) = server_socket.accept()
            print("Added connection: " + str(address))
            print(f"Removed connection: {str(address)} Quit Lobby")
        if len(game_lobby) >= player_amount:
            game = Game(boards[randint(0,999)], game_lobby)
            game_lobby = []
Godot version 3.2.1
in Engine by (29 points)

1 Answer

0 votes

I don't know much about Python, but I have a lot of experience with websocket. Your client does not have a defined port (websocket_url = ""). In this case, I noticed that your server is using Listen(5). The poll () function must be called constantly on the server and on the client, most people use it in _process. As I said I don't know anything about python, so I don't know how to anlizar this while function, but I believe that the poll() should be inside it. I didn't understand this bind ("", 80)...
And lastly I recommend that you use a door with a higher value, for example 1122 or 9988. Doors below 100 can be used by some internal service of the system, I don't know if it's the case of 5 but for security, kick high kkkkk.

by (226 points)

I tried it with too and yet it didn't work, The python script is working with the tcp peer on godot - that thing I know for sure but the problem is that I want to change my client side to websockets for convenience.. So I think that the problem should be either in the client side or with something specific that relates to sockets on the server side.

and 5 isn't my port, the parameter passed to the listen function of a socket in python is the maximum length of the queue I would like to have when the server is busy / when the code is blocked.

In Godot Listen(PORT) is the command that defines the port that the server will listen to.
Port 80 is http. It has to be a door like 1122.

Hi Firty,

Since you know a lot on Websocket. Do you know what is the equivalent for web socket with this UDP command like "while UDP.getavailablepacket_count() > 0"?

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.