The websockets guide here....
https://ci.inria.fr/pharo-contribution/job/EnterprisePharoBook/
lastSuccessfulBuild/artifact/book-result/WebSockets/WebSockets.html

says "Reading and sending are completely separate and independent" and the
class comment says its "full-duplex".  From these I presume sending and
receiving are okay to occur in separate threads, but this is not explicitly
stated, so can someone confirm this?

So for the given example....
| webSocket |
webSocket := ZnWebSocket to: 'ws://echo.websocket.org'.
[ webSocket
   sendMessage: 'Pharo Smalltalk using Zinc WebSockets !';
   readMessage ] ensure: [ webSocket close ].

re-implementing as follows seems to work...
webSocket := ZnWebSocket to: 'ws://echo.websocket.org'.
[ webSocket runWith: [ :msg | Transcript crShow: msg ] ] forkAt: 35.
webSocket sendMessage: 'Pharo Smalltalk using Zinc WebSockets !'.
webSocket sendMessage: 'Another multi-thread echo'.
webSocket close

but that could just be by luck, so I ask.


btw, if I don't send the #close in the last line, after ~30 seconds I get
an error
    ConnectionClosed: Cannot write data
which seems reasonable that the other end timed out and closed the
connection,

but when I send the #close, after ~30 seconds I get an error...
   PrimitiveFailed: primitive #primSocketReceiveDataAvailable: in Socket
failed
which is unfriendly.  What is the best way to neatly stop trying to receive
data when we explicitly close the websocket?

cheers -ben


P.S.  I wonder if when a ZnWebSocket is closed, it might be worthwhile
to do  "role:=#closed"  to provide some visibility of its state in its
GTInspector [Raw] tab..

Reply via email to