britzl / defnet

Defold networking examples
MIT License
64 stars 16 forks source link

No protocol negotiation for websocket (tcp server and client) #4

Closed SupremeTechnopriest closed 5 years ago

SupremeTechnopriest commented 5 years ago

Hello, working on a multiplayer game and I noticed there is no protocol negotiation in the tcp_server. If you build for HTML5 and try to connect to a server you get:

WebSocket connection to 'ws://localhost:8190/' failed: Error during WebSocket handshake: net::ERR_INVALID_HTTP_RESPONSE

Do I need to set up my own negotiation to use this library? Or am I missing something?

Thanks!

britzl commented 5 years ago

In the case of HTML5 all TCP connections will be upgraded to websocket connections by Emscripten and the handshake and everything else will be dealt with by the browser. The basic TCP Server in DefNet does however not handle any of this.

I would recommend that you also take a look at defold-websocket as this provides websocket communication on all platforms, with protocol negotiation done in Lua for non-HTML5 targets.

britzl commented 5 years ago

Oh, and there's Colyseus for Defold which provides both server and client logic for multiplayer games using websockets.

SupremeTechnopriest commented 5 years ago

Thanks for the reply! So I am aware of colyseus, but what I really like about defold is that you can build headless. Id like to be able to create my game logic inside defold. With colyseus you have to implement your own physics, collision... all of it. Defold just becomes a glorified renderer. I want to use an actual defold instance as the server so I can utilize all of defolds features.

It seems that the websocket implementation does not include a websocket server for defold, so in using it I would be forced to implement all the features I want from defold in node.

Do you have any thoughts on this? Is there a better way to make a hybrid server/client in defold? Construct does this really nicely, but unfortunately it uses WebRTC and cant support that many concurrent players. Thanks again!

SupremeTechnopriest commented 5 years ago

I think all we need to do here is add the handshake negotiation logic to the tcp_server. I'm a fairly advanced programmer, but this is my first foray into lua. I think the problem might have already been solved here. This project is no longer maintained, but we could port in the handshake logic. If you don't have the bandwidth to take this on, I'm willing to take a crack at it. Its probably an hour job for you and a 4 hour job for me. LMK

SupremeTechnopriest commented 5 years ago

No worries mate, ended up switching engines. Somethings to thing about perhaps. Ping this issue if you decide to implement this. I'd be interested in revisiting defold.