Web socket connection


#1

I'm trying to connect an iOS app developed in Swift to the socket implementation in OctoPrint. This is new to me. So, I'm struggling a bit with how to get connected.

First, I'm using this library: https://github.com/tidwall/SwiftWebSocket

I'm trying to simply figure out where to connect to the server - the address. (Baby steps here.) I've tried the following:

wss://octopi.local:8081 -> I thought this was the default location
wss://octopi.local:5000

And, then I found a specific directory that it might be located within and I tried that:

wss://octopi.local:8081/socksjs/websocket
wss://octopi.local:5000/socksjs/websocket

I'm expecting that the next thing that I will need to do is pass an API key, but I'm just wanting to get an authentication error at this point! :grinning:

Please let me know if my approach is even correct and what the correct address would be. Again, this is the first time I've really dealt with web sockets. Thanks!


#2

I haven't exercised many of the OctoPrint interfaces, only the REST one.

I know that there's a JavaScript client API which includes a socket interface. Although the document doesn't indicate endpoints and such, the code itself might. Reading through that, I'm not seeing anything that looks like defining arguments or anything.

Perhaps @foosel can assist.


#3

Might be too late for this reply. You may find an example in the source code of OctoPod. It is open source and uses Starscream to connect to what Tornado calls "raw websockets". This class is what connects to the raw websocket.

An example of URL to connect to is: http://octopi.local/sockjs/websocket