Network Library with Websockets

Got an idea for enhancing SpiderBasic? New command(s) you'd like to see?
tj1010
Posts: 201
Joined: Wed May 27, 2015 1:36 pm
Contact:

Re: Network Library with Websockets

Post by tj1010 »

Thorium wrote: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?
I just do UTF-8 JSON with this. I'd like to have cleaner code by having a native library though. I do push out to clients based on which room or table they are at when a distributed event happens. Polling with http requests would choke a server and besides my server isn't same-origin. It's on a dedicated box with a dedicated IP.
Fred
Site Admin
Posts: 1506
Joined: Mon Feb 24, 2014 10:51 am

Re: Network Library with Websockets

Post by Fred »

I didn't looked much to websockets, how do you see the SpiderBasic API for it ? Which features would be needed ?
Thorium
Posts: 10
Joined: Mon Dec 22, 2014 3:30 pm

Re: Network Library with Websockets

Post by Thorium »

Fred wrote:I didn't looked much to websockets, how do you see the SpiderBasic API for it ? Which features would be needed ?
It's much like TCP sockets for networking. We would need a network library like PureBasics. One of the differences to normal TCP sockets is that it starts out as a http connection, which is then upgraded to a websockets connection with a handshake.
Another difference is that data is transfered as a so called frame. A frame can be in binary format or in text format. It's much like a packet on normal TCP sockets.

So we need PureBasics network library in SpiderBasic with the added feature of distinguishing between binary data and text data.

Additionaly a websockets server for PureBasics network library would be very handy. Here is a lib that supports TLS: https://libwebsockets.org/index.html
There are allready websockets server examples on the PureBasic forums but non supports TLS, which is very important today.
tj1010
Posts: 201
Joined: Wed May 27, 2015 1:36 pm
Contact:

Re: Network Library with Websockets

Post by tj1010 »

Rough idea:

Code: Select all

integer=CreateNetworkConnection(URL string);don't worry about ws or wss just return false if invalid cert or connection fail
bool=CloseNetworkConnection(Connection integer)
bool=GetNetworkData(Connection integer,CallBack function);callback as parameter
bool=SendNetworkString(Connection integer,String string)

Let user encode binary with Asc and Chr. Spec allows Array, Blob, and String to be exchanged with send() but string-only keeps with the theme of SB
I made this in minutes so I may have missed something.
Thorium
Posts: 10
Joined: Mon Dec 22, 2014 3:30 pm

Re: Network Library with Websockets

Post by Thorium »

tj1010 wrote: Let user encode binary with Asc and Chr. Spec allows Array, Blob, and String to be exchanged with send() but string-only keeps with the theme of SB
SB now has memory commands, so the theme is not strings only.
Encoding them with Asc and Chr would be terrible. Base64 should be used to encode binary data into a string. However i dont see why we would not want binary data.
The web was text based way to long and is heading in a binary direction.
tj1010
Posts: 201
Joined: Wed May 27, 2015 1:36 pm
Contact:

Re: Network Library with Websockets

Post by tj1010 »

This socket code and the official http request function need to be tested on android and ios. Maybe they don't have same-origin policy. Else SB team will need to do ios&android sockets or at least HTTP POST support. The problem with GET only is most servers have tight limits on GET buffer size.
Post Reply