Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

websocket doesn't work under bun #454

Open
glorand-harmonicinc opened this issue Mar 7, 2024 · 2 comments
Open

websocket doesn't work under bun #454

glorand-harmonicinc opened this issue Mar 7, 2024 · 2 comments

Comments

@glorand-harmonicinc
Copy link

glorand-harmonicinc commented Mar 7, 2024

Hi,
If I run the attached example websocket.zip with nodejs it works:

$ node server.js 
Thu Mar 07 2024 09:39:55 GMT+0000 (Coordinated Universal Time) Server is listening on port 8080
Thu Mar 07 2024 09:40:13 GMT+0000 (Coordinated Universal Time) Connection accepted.
Received Message: 397030
Received Message: 10038402
Received Message: 6845227
Received Message: 2955012
Received Message: 5366268
Received Message: 4668963
$ node client.js 
WebSocket Client Connected
Received: '397030'
Received: '10038402'
Received: '6845227'
Received: '2955012'
Received: '5366268'
Received: '4668963'

, but with bun it doesn't:

$ bun server.js 
Thu Mar 07 2024 09:52:10 GMT+0000 (Coordinated Universal Time) Server is listening on port 8080
Thu Mar 07 2024 09:52:15 GMT+0000 (Coordinated Universal Time) Connection accepted.

$ bun client.js

Same result if I also use nodejs for the client part.

Any idea?

Probably not related to this issue but I also tried nodejs for the server and bun for the client and following error occurs (I have added headers dump in the log trace):

$ node server.js 
Thu Mar 07 2024 10:00:12 GMT+0000 (Coordinated Universal Time) Server is listening on port 8080
Thu Mar 07 2024 10:00:17 GMT+0000 (Coordinated Universal Time) Received request for / with headers {"host":"localhost:8080","sec-websocket-key":"ku8AfoxHZGmLPCmPCxoxlQ==","sec-websocket-protocol":"echo-protocol","sec-websocket-version":"13","upgrade":"websocket","connection":"keep-alive","user-agent":"Bun/1.0.30","accept":"*/*"}
$ bun client.js 
Connect Error: Error: Server responded with a non-101 status: 404 Not Found
Response Headers Follow:
date: Thu, 07 Mar 2024 09:54:38 GMT
connection: keep-alive
keep-alive: timeout=5
transfer-encoding: chunked
@theturtle32
Copy link
Owner

Thanks for the report! I haven't tried Bun before. It's likely that there's some API in the http(s) modules that they didn't replicate exactly and its tripping up some expectation in WebSocket-Node. I don't have a lot of time at the moment to dig into it, unfortunately. :-(

@rgillan
Copy link

rgillan commented Jul 11, 2024

So one of the nice things about Bun is the websocket client/server is natively supported, and using highly performant uWebsockets. The client construct is very similar but the server is very different (although not hard to refactor). Also supports native pub/sub capability.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants