Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  nodelist  faq  login

Help! I'm trapped in a Chinese computer factory!

programming / comp.lang.smalltalk.dolphin / WebSocket package release

o WebSocket package releaseZenchess

Subject: WebSocket package release
From: Zenchess
Newsgroups: comp.lang.smalltalk.dolphin
Date: Sat, 31 Aug 2019 10:02 UTC
X-Received: by 2002:a0c:dd83:: with SMTP id v3mr12921458qvk.105.1567245727027;
Sat, 31 Aug 2019 03:02:07 -0700 (PDT)
X-Received: by 2002:a81:1ace:: with SMTP id a197mr13836580ywa.296.1567245726818;
Sat, 31 Aug 2019 03:02:06 -0700 (PDT)
Newsgroups: comp.lang.smalltalk.dolphin
Date: Sat, 31 Aug 2019 03:02:06 -0700 (PDT)
Injection-Info:; posting-host=2600:8804:1200:6600:ed56:881d:8ff9:9d69;
NNTP-Posting-Host: 2600:8804:1200:6600:ed56:881d:8ff9:9d69
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <>
Subject: WebSocket package release
From: (Zenchess)
Injection-Date: Sat, 31 Aug 2019 10:02:07 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 77
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 (


  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.

  This does not integrate with other web frameworks, though I guess it could be made to.   This is just a standalone websocket server that you can connect to like ws:// in your html javascript or from a websocket client program.  You could "integrate" this into a web server by hosting your web server on the same domain and just running this websocket server in parallel.  I've been using 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:

  The data you send with sendByteArray:toSocket: will arrive in Little Endian format, so you'll have to read it with methods like in javascript: dv.getFloat32(0, true);   a method on dataview in javascript , the true argument is for little endian = true.

  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.
chatroom startServer.

You can test the chat server, which just echoes back the text you send it, at this url:
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.


rocksolid light 0.7.2