Gun: socket.io conflict error on header?

Created on 27 Nov 2016  路  15Comments  路  Source: amark/gun

I did some simple test on setup some basic server using express and socket.io with gun. I get header error some reason. I wonder if this is bug or the way it handle network error access.

Most helpful comment

Oh. I using chrome for testing and nodejs. Not sure how handle web browser to handle that. You can check out but it still very early develop. github > lightnet > bes-threejs. Current main is babylonjs_game. I have not work on gundb since it long ways to go. Need to build the editor for it.

All 15 comments

As in gun can't run alongside a socket.io server? Or that when using socket.io with gun it does not work? (Currently gun has no socket.io adapters and thus will not work with it. But it isn't hard to build one.)

I am just running both of them but just got an error on header that all. Reason it chat on socket.io and gun for database but depend what I building. Or Socket.io for game network design but lag but run local not site for what I am design to create game editor, server, client type of build.

@Lightnet The WebSocket driver that comes bundled with gun is a very thin layer above window.WebSocket, and probably (I'm guessing here) isn't compatible with the socket.io protocol.

Although gun doesn't try to be compatible with socket.io out of the box (as @amark mentioned, a plugin can be built for it), it does run a socket server and might be causing issues when used with socket.io.

Do you have a stack trace you could post here, or maybe some code to reproduce the error?

Well it ok I guess. I did simple setup. Express, socket.io and gun. Bare minimal code for server side and client. As well the current latest ones.(stable release)

socket.io.js:6605 WebSocket connection to 'ws://127.0.0.1/socket.io/?EIO=3&transport=websocket&sid=r1jSm_QMD5zc20z_AAAA' failed: Invalid frame header

I was able to reproduce the bug... looks like running the two WebSocket servers attached to the same http server (socket.io and gun) will cause an issue.

I'm investigating to see if gun is the Invalid frame header culprit. Meanwhile, this is the code I'm testing with:

server.js

var server = require('http').Server();
var Gun = require('gun');
require('socket.io')(server);

var gun = Gun();

gun.wsp(server);

server.listen(8080);

index.html

<!DOCTYPE html>
<html lang='en'>
<head>
  <meta charset='UTF-8'>
  <title>Socket.io/Gun clash</title>
</head>
<body>
    <script src='http://localhost:8080/socket.io/socket.io.js'></script>
    <script>
        const socket = io('http://localhost:8080');
    </script>
</body>
</html>

Logs:

WebSocket connection to 'ws://localhost:8080/socket.io/?EIO=3&transport=websocket&sid=7MusFDtQFvZGBZloAAAD' failed: Invalid frame header

Apparently gun sees the messages sent by socket.io (ws.js), but considers them invalid and doesn't attempt a reply (wsp.js).

I don't see anywhere gun responds without running messages through the same validation, meaning the troublesome frame header might be coming from a lower level library.

With the code above, socket.io messaging works both ways alongside gun.

If it's just the warning, we're probably not going to pursue it for now. @Lightnet is socket.io messaging working on your setup?

Thanks for taking the time to investigate this @PsychoLlama

Sure thing @ctrlplusb! We wanna make sure gun plays nice with others :smile:

Thanks @PsychoLlama !

@ctrlplusb what are you working on? I'd love to hear about it. Looks like you got some nice/popular open source tools yourself!

Well I am not sure it up to you. But it worth doing if someone wanted to used socket.io and gun at the same time. It has to be friendly but since I am not sure since it open idea. I not that good with coding that detail of work how header works.

@Lightnet good news, @PsychoLlama and I just made 0.5 a lot easier for adding transport plugins, here is an example of how easy it would be to receive messages:

ws.onmessage = function(msg){
    gun.on('in', JSON.parse(msg.data));
};

Also @Lightnet what are you working on?

where that "ws.onmessage"? it on the update?

Working Babylonjs 3D web game sandbox dungeon/adventure theme prototype. Very early stuff. Just setting thing up later for editor web build.

ws.onmessage is just the Browser's API for listening to a WebSocket connection, kinda like element.onclick = function(){} is.

@Lightnet Nice! I would love to see that! Any early prototypes/demos? You'll definitely want to use the bleeding edge 0.5 branch as it has been engineered specifically for gaming and performance!

Oh. I using chrome for testing and nodejs. Not sure how handle web browser to handle that. You can check out but it still very early develop. github > lightnet > bes-threejs. Current main is babylonjs_game. I have not work on gundb since it long ways to go. Need to build the editor for it.

Given Jesse's earlier analysis (here: https://github.com/amark/gun/issues/282#issuecomment-263463918 ) that was able to get the two working side by side, I'm gonna go ahead and close this issue.

Made any progress on your game, though?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

amark picture amark  路  3Comments

nolotus picture nolotus  路  3Comments

linonetwo picture linonetwo  路  4Comments

ctrlplusb picture ctrlplusb  路  6Comments

bugs181 picture bugs181  路  3Comments