WebSocket package releaseFrom: ZenchessNewsgroups:
Sat, 31 Aug 2019 10:02 UTC
View all headers
Hello. Very excited that I've been able to get WebSocket working in Dolphin, turned out my idea of how hard it would be prevented me from making it more than the actual difficulty :)
Tested in the latest 7.0 release (188.8.131.52).
I didn't implement a whole lot of the protocol, but it should work for most cases. Notably you cannot send or receive data payloads greater than 65535 byte length. Allowing for this would not be a ton of extra work.
as they have Windows Server 2012 and Windows Server 2016 you can run Dolphin on a vm.
To use, subclass WebSocketServer and add whatever your app requires. You can send text to a socket (json, whatever) with the SendText:toSocket: method.
You can send bytes with sendByteArray:toSocket:
You would send a float like this on the smalltalk side like:
data := ByteArray new: 4.
data floatAtOffset: 0 put: 121209.12.
For a bigger payload, you can send it all in one bytearray, like:
data := ByteArray new: 8.
data floatAtOffset: 0 put: 1210210.10.
data floatAtOffset: 4 put: 992992.2.
If you want to make something like a multiplayer web game, you can create a process that periodically sends data to all sockets every 32 milliseconds or whatever.
To test the framework with the chat room example in a workspace evaluate
chatroom := WebsocketEchoChatroomTest new.
You can test the chat server, which just echoes back the text you send it, at this url: https://www.websocket.org/echo.html
in location: put ws://localhost:2048.
When you are done running the server evaluate chatroom stopServer.
The entire example takes place in the onReceivedData: method.
I haven't put a ton of work into this, it seems to work fine so far but if you fix any bugs, expand it, or notice something wrong, please share.
Note on performance: It seems to perform pretty darn well for my use case: (multiplayer web games). In one test I spawned 500 'bots' that would move around, sending all of their xposition(float), yposition(float), rotation(float), and objectid (16 bit integer) every 32 milliseconds to all connected clients. I've ran similar tests in nodejs websocket frameworks and they would end up lagging with all that data send.
I also tried 100 'bots' and then connected to the server with about 30 browser windows, and noticed no lag in the gameplay. So it seems to perform pretty well.