Page 1 of 1

Compression & Network libraries

Posted: Sat Feb 15, 2020 12:01 pm
by kingwolf71
I am new to the spiderbasic world; but old timer with PureBasic
The compression and network libraries are a sore miss
Is there a timeline of these features ever being part of SB ?

Re: Compression & Network libraries

Posted: Thu Feb 20, 2020 3:30 am
by poshu
There won't be a PB compatible network library : HTML5 can't use traditional socket and is limited to websocket support.

That being said, here is my websocket module for SpiderBasic

Code: Select all
DeclareModule Websocket
   Declare Open(Adress.s,*OnMessageCallback,*OnOpenCallback,*OnErrorCallback,*OnCloseCallback)
   Declare Send(message.s)
   Declare Close()
   Declare IsSupported()

Module Websocket
   ; Public Procedures
   Procedure Open(Adress.s,*OnMessageCallback,*OnOpenCallback,*OnErrorCallback,*OnCloseCallback)
      Protected Result
      ! websocket = new WebSocket(v_adress);
      ! websocket.onopen = function(evt) { p_onopencallback(evt) };
      ! websocket.onclose = function(evt) { p_onclosecallback(evt) };
      ! websocket.onmessage = function(evt) { p_onmessagecallback(evt) };
      ! websocket.onerror = function(evt) { p_onerrorcallback(evt) };
      ! v_result = websocket;
      ProcedureReturn Result
   Procedure Send(message.s)
      ! websocket.send(v_message);
   Procedure Close()
      ! websocket.close();
   Procedure IsSupported()
      Protected Result
      !if (window.WebSocket){
      !   v_result=1;
      ProcedureReturn Result

CompilerIf #PB_Compiler_IsMainFile ; Example
   Procedure onOpen(evt)
   Procedure onClose(evt)
      Debug "onClose"
   Procedure onMessage(evt)
      Protected MessageFromWs.s
      ! v_messagefromws =;
      Debug MessageFromWs
   Procedure onError(evt)
      Debug "onError()"
   websocket::Open("ws://", @onMessage(),@onOpen(),@onError(),@onClose())

And you can find a (very clean) websocket server written by David Vogel for PureBasic right there : .

I've been using this pair for years in a few of my projects (including an artistic installation with hundreds users connected at once), so I can vouch for its stability.