Page 1 of 2
Network Library with Websockets
Posted: Tue May 05, 2015 1:32 pm
by Thorium
Would be cool to have a network library which works with Websockets.
Re: Network Library with Websockets
Posted: Sun Sep 13, 2015 8:03 pm
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..
Re: Network Library with Websockets
Posted: Fri Feb 12, 2016 11:21 am
by Rings
Any news on WEBSOCKETS ?
does anyone have it implemented already ?
(like
http://www.purebasic.fr/english/viewtop ... =Websocket)
Re: Network Library with Websockets
Posted: Fri Feb 12, 2016 12:43 pm
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
Re: Network Library with Websockets
Posted: Sat Feb 13, 2016 11:59 am
by spidernet
Thanks Peter, very useful code.

Re: Network Library with Websockets
Posted: Sat Feb 13, 2016 2:26 pm
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
Re: Network Library with Websockets
Posted: Mon Feb 15, 2016 6:49 am
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...
Re: Network Library with Websockets
Posted: Mon Feb 15, 2016 8:13 pm
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.
Re: Network Library with Websockets
Posted: Thu Mar 24, 2016 2:00 am
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.
Re: Network Library with Websockets
Posted: Tue Apr 05, 2016 1:31 pm
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?