Davidobot / love.js

LÖVE ported to the web using Emscripten, updated to the latest Emscripten and LÖVE (v11.5)
MIT License
605 stars 27 forks source link

Help request with networking #95

Closed Mrestof closed 1 week ago

Mrestof commented 2 weeks ago

Hi. I'm trying to send a few integers and strings from the LOVE app to some hand-written server via internet.

Preferred method would be an HTTP request, but at this point I'm in search of any method of sending the data at all, be it over socket, WebSocket or other. Only requirement is that I can ensure the data arrives unaltered, so theoretically, TCP would fit.

I've tried making HTTP requests via socket.http builtin module to a remote website. I've tried making socket tcp connection via socket module to both: a simple local tcp server and a simple local WebSocket server; both written in Python.

In the second case with socket connection, the servers notice some attempts of establishing a connection (inconsistently for some reason), but the test message is not transferred. For both servers, the client LOVE app just logs: WebSocket connection to 'ws://127.0.0.1:12345/' failed: WebSocket is closed before the connection is established.. In case with simple tcp server, it receives the HTTP GET request as a text that is similar to the request that is used to initialize a WebSocket connection, but not the test message. In case with simple WebSocket server, it throws an exception with a message: websockets.exceptions.ConnectionClosedError: no close frame received or sent.

I will appreciate any help, and thanks in advance for your time.

Mrestof commented 1 week ago

I've figured it out by using Love.js-Api-Player, it was pretty straightforward. I made a function in JS that used fetch to send http requests, I include the function to the generated by lua.js website and then call that function from Lua code and it works perfectly! Hope it helps somebody out there.