Group Abstract Group Abstract

Message Boards Message Boards

2
|
12.1K Views
|
3 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Support for Secure (Web) Sockets in the Wolfram Language?

Hello everyone!

I'm trying to connect to a service that uses Websockets (RFC 6455), specifically, Secure Websockets, that work over HTTPS (this information will be useful later).

I've tried many ways of doing so, first, using a wss:// does not work. Of course, because SocketConnect is meant for a raw TCP socket.

In[1]:= SocketConnect["wss://echo.websocket.org"]
During evaluation of In[1]:= SocketConnect::addrspec: The host specification echo.websocket.org is wrong because it is missing the port specification    
Out[1]= $Failed

One workaround was to use :443 at the end to specify the "secure" port.

In[2]:= SocketConnect["echo.websocket.org:443"]
Out[2]= SocketObject["TCP-<<UUID>>"]

Which worked fine, but later on, when sending a "homemade" Opening Handshake (Section 1.3 from RFC6455), one big catastrophic thing happened, the SocketConnect works over HTTP, and not HTTPS. The following Cloudfare message told me a very unhappy message for me.

400 Bad Request - Plain HTTP request sent over HTTPS.

I've tried using the internal SocketLink library, but with no success, because it doesn't work with HTTPS as well.

In[3]:= Needs["SocketLink`"] (* and some stuff i tried.. *)
Out[3]= ¯\_(ツ)_/¯ (* also uses HTTP, and crashes the kernel sometimes *)

My last resort would be to write a C external function for dealing with Websockets and Secure Websockets, but I'm here asking for any other possible and easier options.

So.. what should I do? Should I wait for a SecureSocketConnect? Is there any workaround that does not involve using other programming languages? Any help would be extremely appreciated!

Thanks!

Pedro Cabral.

POSTED BY: Pedro Cabral
3 Replies

Hello Pedro,

Rather than writing that in C, you could use Python's websockets library, so in the meantime you find a solution you can get this done.

I'm sure there is a better way to do it, but you can play around with this

First install websockets:

$ pip3 install websockets

Then:

nect(uri) as websofcket=: (
 + s)^2 +    3*s^   (a3w/ait websos)k^e(t1./s2e)n*dt(h' H-e l4l*os *W(1l d+! 's))
 +     
output =   a w a i t3 *wse^b(s1o/c2k)e*t(.1r e+ vs())^(
/2)*th + yn
io.ge t _ e v e nst^_2l*otohp^(2)).)r/u(n8_ u(nst^i(l3_/c2o)m*p(l1e t+e (ss)e^n(d1(/)2))
1 +
 s)^(1/2) 
 
"
 
         s^(1/2)*thx)t^e3r)n)a;l
 
         s^(1/2)*thx)t^e3r)n)a;lSessifofn [=" PIyntvheorns"e]L
placoeuTtrpaunts f=o rEmx[tSeerrniaelsE[vfa,l u{ast,e [Isnefsisniiotny,,  s2e0n}d]] 

Output should be equal to "Hello World!"

POSTED BY: Nicolò Monti

Hi Pedro,

have you been able to come up with a working solution?

POSTED BY: Philipp Winkler

I am also very interested in this for streaming quotes from exchanges and already made a feature request. Hopefully there will be a build in solution in the not too distant future.

POSTED BY: Philipp Winkler
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard