Got an idea for enhancing SpiderBasic? New command(s) you'd like to see?
Posts: 21
Joined: Wed May 01, 2019 10:14 am

Compression & Network libraries

by kingwolf71 Sat Feb 15, 2020 12:01 pm

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 ?
Posts: 96
Joined: Mon Feb 24, 2014 11:46 pm

Re: Compression & Network libraries

by poshu Thu Feb 20, 2020 3:30 am

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.
Return to Feature Requests and Wishlists

Who is online

Users browsing this forum: No registered users and 4 guests