cosmopolitan icon indicating copy to clipboard operation
cosmopolitan copied to clipboard

redbean: add websocket support

Open dcrck opened this issue 9 months ago • 8 comments

Cleans up #967 by adding some tests for the isutf8 changes and websocket handshake, removing unused variables, and fixing the failing autobahn-testsuite test.

This also adds a basic websocket echo server to the redbean-tester at /ws.

I'd like to add more tests but I don't know the best way to do so:

  • get raw socket communication working in redbean_test.c, or
  • create a ws_test.lua file to run the autobahn-testsuite against the server.

Advice and feedback is appreciated. I am new to sockets programming. I'm in the Discord all the time, or can respond to questions/feeback here if that's preferable. :slightly_smiling_face:

Closes #439

To run more detailed tests (once o//test/tool/net/redbean-tester is running):

docker run -it --rm -v "${PWD}/config:/config" -v "${PWD}/reports:/reports" -p 9001:9001 --network host crossbario/autobahn-testsuite wstest -m fuzzingclient -s /config/fuzzingclient.json

config/fuzzingclient.json should contain:

{
  "outdir": "./reports/servers",
  "servers": [
    {
      "url": "ws://127.0.0.1:8080/ws"
    }
  ],
  "cases": ["*"],
  "exclude-cases": [],
  "exclude-agent-cases": {}
}

Results will then be available at ${PWD}/reports/servers/index.html

dcrck avatar Mar 22 '25 02:03 dcrck

@dcrck, thank you for picking up this work. I'm confused a bit: is this PR a mix of commits from #967 and tests/cleanup that you added? Shouldn't the original commits retain all their metadata with your changes layered on top of them?

pkulchenko avatar Mar 22 '25 03:03 pkulchenko

I'm confused a bit: is this PR a mix of commits from https://github.com/jart/cosmopolitan/pull/967 and tests/cleanup that you added? Shouldn't the original commits retain all their metadata with your changes layered on top of them?

That would probably be a better way to do it, but I didn't have access to the original repository containing the work so I just copied over all the changes to my repository. I can re-organize it so it contains their changes.

dcrck avatar Mar 22 '25 03:03 dcrck

@pkulchenko should be updated now

dcrck avatar Mar 22 '25 03:03 dcrck

Looks good; thank you for incorporating those changes!

@jart, do you have a copyright assignment from @wingdeans (from #967)?

pkulchenko avatar Mar 22 '25 03:03 pkulchenko

@jart it's been about a month since I opened this PR, can you please check on @wingdeans' copyright assignment (should be #967 )? Thank you!

dcrck avatar Apr 19 '25 00:04 dcrck

Sure I'll take a look this week.

jart avatar May 05 '25 14:05 jart

Any updates on this feature? I would love to see it merged. Thank you!

atgreen avatar Aug 19 '25 17:08 atgreen

Hi there. I was interested in adding websockets to redbean in 2022 (https://github.com/jart/cosmopolitan/issues/439). Now that this PR landed, I have questions that aren't answered in the readme. (In fact, the readme still states that websockets "may be added in the future" FYI. Given the forking nature of redbean as a webserver, how does this work with websockets (ws)? If inbound ws are each handled by a different process, then how do they communicate with each other? If a single process is handling all ws, how does one program their interaction? Is there a C or Lua API for doing that? Are there any benchmarks or resource-usage statistics available? I'd be happy to pitch in, especially for the last one. I'm no Kyle Kingsbury but I can test a thing.

javajosh avatar Aug 27 '25 03:08 javajosh