Websocket Questions

162 views
Skip to first unread message

Chris

unread,
Oct 19, 2020, 7:26:09 AM10/19/20
to DroidScript
Hi there, 

Just a couple of quick questions regarding the Websocket Server:

1) Is it possible to close a websocket connection (from the DS/server side)?

2) Is it possible to send/receive binary (blob/arraybuffer) rather than strings (like the HTML5 Websocket API does)?

I don't see a way to access a socket object (only the server object).

Thank you :)

Dave

unread,
Oct 19, 2020, 8:28:20 AM10/19/20
to DroidScript
Hi Chris,

It's not currently possible to close a socket, why do you want to do that?

You should be able to send binary data by converting it to base64 and back using the atob() and btoa() javascript funcs

Kallikratidas

unread,
Oct 28, 2020, 8:27:15 AM10/28/20
to DroidScript
Well, it would be possible in general if DS provided complete control over the WebServer object, as nodeJS does. Another problem I am facing with DS WebServer is that there is trouble sending data to a specific client. Yes... Of course, you can specify the IP address... But what's happening when you have to do with two clients owning the same IP? (eg. in the same device) I completely understand that DS WebServer is not made up for high level developing apps or for eve for a data serving system, but anyway, it could afford many improvements, at least regarding the specification of the recipient of a text message. I would advise you to make the WebServer object-oriented, as regarding the clients, exactly as NodeJS has them. That would allow every developer to have more options than just serving real-time data with no basic options (such as maxPackageSize and an authentication system to permit or reject a connection) and no determination.

Regards

Chris

unread,
Nov 2, 2020, 9:20:04 AM11/2/20
to DroidScript
Hi Dave,

Thank you - I would like to immediately close sockets (on connection) that are not coming from localhost for security purposes. In this case the app opens a port for other apps on the same device (only) to connect to. There is no other way I can see to restrict access to specific IPs.

I am able to use this method of base64 encoding successfully, but unfortunately it's less efficient (slower) than using binary transmission as it ads an overhead in terms of increased packet size and processing time (for encoding/decoding) - which matters in my case as I have an atypical use-case of sending/receiving files such as images.

Another thing I noticed is that the DS websocket server seems to drop incoming packets over ~15kb in size (which would be about 15000 characters of a string), whereas it can send larger packets, which can be received fine (from say an HTML websocket implementation). Not sure if that's a bug or a parameter set lower than usual. Obviously this can be solved by manually splitting large strings into smaller packets... which actually has some advantages (such as reporting progress transmitted).


Thanks again :)

Dave

unread,
Nov 2, 2020, 10:14:46 AM11/2/20
to DroidScript
Hi Chris,

I've added a new Disconnect() method to the WebServer object which will be in the next beta release (this week)

I'll try to increase/control the buffer sizes too

Chris

unread,
Nov 13, 2020, 12:56:27 PM11/13/20
to DroidScript
serv.Disconnect(ip, id);

Tested and working perfectly  :) 

Thanks for adding this Dave, much appreciated.
Reply all
Reply to author
Forward
0 new messages