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

SubjectAuthor
o WebSocket package releaseZenchess

1
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)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!feeder.usenetexpress.com!feeder-in1.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!a13no634971qtd.0!news-out.google.com!d29ni141qtg.1!nntp.google.com!a13no634961qtd.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
Newsgroups: comp.lang.smalltalk.dolphin
Date: Sat, 31 Aug 2019 03:02:06 -0700 (PDT)
Complaints-To: groups-abuse@google.com
Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=2600:8804:1200:6600:ed56:881d:8ff9:9d69;
posting-account=r2EEkwoAAADz3M0x3Szspui4wqseZF5h
NNTP-Posting-Host: 2600:8804:1200:6600:ed56:881d:8ff9:9d69
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <713d100a-7c8b-47ca-98b0-2be9d825dbf4@googlegroups.com>
Subject: WebSocket package release
From: zench...@gmail.com (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 :)

https://drive.google.com/open?id=11XhsFwTaCaiwz65a1xVQhr2BWAQXZYJ0

  Tested in the latest 7.0 release (7.0.57.2).

  Notes:

  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://domain.com:2048 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 https://www.vultr.com/ as they have Windows Server 2012 and Windows Server 2016 you can run Dolphin on a vm.

  Instructions:

  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: 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.





 


1
rocksolid light 0.7.2
clearneti2ptor