Network Library with Websockets

Got an idea for enhancing SpiderBasic? New command(s) you'd like to see?
Thorium
Posts: 10
Joined: Mon Dec 22, 2014 3:30 pm

Network Library with Websockets

Post by Thorium »

Would be cool to have a network library which works with Websockets.
tj1010
Posts: 218
Joined: Wed May 27, 2015 1:36 pm
Contact:

Re: Network Library with Websockets

Post by tj1010 »

I have to write my own because I can't wait.. It sucks..

to do it from the editor you have to basically wrap everything in functions with all the class and callback stuff escaped, then set states with the callbacks which you monitor with timers. A lot of time wasted..
User avatar
Rings
Posts: 6
Joined: Tue Feb 25, 2014 9:44 am

Re: Network Library with Websockets

Post by Rings »

Any news on WEBSOCKETS ?

does anyone have it implemented already ?
(like http://www.purebasic.fr/english/viewtop ... =Websocket)
User avatar
Peter
Posts: 1197
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: Network Library with Websockets

Post by Peter »

Perhaps this is a starting point for you:

Code: Select all

Procedure doSend(message.s)
  Debug "Sending: " + message
  ! websocket.send(v_message);
  Debug "-------"
EndProcedure

Procedure onOpen(evt) 
  Debug "onOpen()"
  ; Debug evt
  Debug "-------"
  doSend("WebSocket rocks")
EndProcedure

Procedure onClose(evt)
  Debug "onClose"
  ; Debug evt
  Debug "-------"
EndProcedure

Procedure onMessage(evt)
  Debug "onMessage()"
  Protected MessageFromWs.s
  ! v_messagefromws = v_evt.data;
  Debug "MessageFromWs: " + MessageFromWs
  Debug "-------"
  ! websocket.close();
EndProcedure

Procedure onError(evt)
  Debug "onError()"
  ; Debug evt
  Debug "-------"
EndProcedure

Procedure Dummy()
  onOpen(0)
  onClose(0)
  onMessage(0)
  onError(0)
EndProcedure

Procedure initWebSocket(wsUri.s)
  ! websocket = new WebSocket(v_wsuri);
  ! websocket.onopen = function(evt) { f_onopen(evt) };
  ! websocket.onclose = function(evt) { f_onclose(evt) };
  ! websocket.onmessage = function(evt) { f_onmessage(evt) };
  ! websocket.onerror = function(evt) { f_onerror(evt) };
EndProcedure


initWebSocket("ws://echo.websocket.org/")
Greetings ... Peter
spidernet
Posts: 72
Joined: Tue Feb 02, 2016 3:50 pm

Re: Network Library with Websockets

Post by spidernet »

Thanks Peter, very useful code. :)
sworteu
Posts: 18
Joined: Sun Feb 07, 2016 9:49 am

Re: Network Library with Websockets

Post by sworteu »

I'm currently working on modules on github. I'll be creating a module for WebSockets too.

It's not yet ready but it can be found here once it is: https://github.com/sworteu/XJS
User avatar
SinisterSoft
Posts: 77
Joined: Sun Apr 06, 2014 11:41 pm
Location: Preston, UK
Contact:

Re: Network Library with Websockets

Post by SinisterSoft »

@sworteu Great modules, thanks for sharing. Local and session storage should be 'built-in' imho, so @fred should take a look at your code...
sworteu
Posts: 18
Joined: Sun Feb 07, 2016 9:49 am

Re: Network Library with Websockets

Post by sworteu »

SinisterSoft wrote:@sworteu Great modules, thanks for sharing. Local and session storage should be 'built-in' imho, so @fred should take a look at your code...
They are not yet completed. Code may be build-in but that's up to fred.
I'd make spiderbasic same as purebasic if i where fred.
tj1010
Posts: 218
Joined: Wed May 27, 2015 1:36 pm
Contact:

Re: Network Library with Websockets

Post by tj1010 »

Just to add: use wss:// for HTTPS/TLS enabled domains and only when the certificate is signed by a CA. Modern browsers need modified to support self-signed or revoked certificates anywhere including websocket implementations.

I'd imagine Fred&Team will add this at some point considering most browser stuff uses push type notifications(server sends to clients instead of clients polling/timed-requesting and stressing the server) these days and most web hosts don't support long-polling HTTP connections even if over ajax.
Thorium
Posts: 10
Joined: Mon Dec 22, 2014 3:30 pm

Re: Network Library with Websockets

Post by Thorium »

Now that SB supports memory operations i am reevaluating if it fits a project i plan to start soon.
Only thing missing for me is websocket support.
Anyone has allready done a module for binary websockets?
Post Reply