Help With Network API

This topic is primarily for Brad, or anyone else familiar with the Network API:

My main question is, what address does a WebSocket client connect to in order to establish a link with Cantabile’s Network Server? Context and background below…

I recently purchased a Stream Deck and see a lot of potential using it as a controller for Cantabile. My hope is to develop a custom application that acts as an interface between the Stream Deck and Cantabile, so the buttons can be customized based on the current song configuration. For example, button one could open the GUI for the first plugin in the first rack, and always show a specific graphic to represent whatever that plugin is in the current song.

I am proficient in C# and C++, not so much in JavaScript, and barely at all when it comes to Web technologies, including WebSockets. So, my thought was to create this app in C#. I have found a .NET library (StreamDeckSharp) that does a great job of controlling and responding to the Stream Deck. To connect to Cantabile, there is a .NET class called System.Net.WebSockets.ClientWebSocket that seems to be a logical solution, using the WebSocket API. However, I am having a hard time getting it to connect.

The ClientWebSocket class can only connect using a URI that starts with “ws://” or “wss://”. All of the examples I can find regarding the Network/WebSocket API mention using “http://localhost:35007”. I can connect successfully using that address in Chrome - I get the built-in web interface. But, how do I connect using a WebSocket? I tried “ws://localhost:35007”, but the connection fails. Specifically, with this code:
_socket = new ClientWebSocket();
await _socket.ConnectAsync(new Uri(“wss://localhost:35007”), CancellationToken.None);
Debug.WriteLine(“Connected”);

The 3rd line above is never reached - the connection is never established. Maybe I am going about this all wrong, but the code above is based on several examples I have found online for using the ClientWebSocket class.

I am open to suggestions on taking a completely different approach, but the WebSocket connection seems like the simplest, cleanest way to do this from within C#. I can easily process the JSON messages if only I can get them!

Any help greatly appreciated.

Tom B

Hi Tom,

The web socket api is at the end point /api/socket so the full url you want is something like:

ws://localhost:35007/api/socket

The Network API is documented here: https://www.cantabilesoftware.com/netapi/ (but neglects to mention the socket end point. Oops :slight_smile: ).

Also, for reference the JS client side implementation is available here.

Brad

Thank you, Brad. That did the trick.

I have also played around with the JS api, and am torn on which way to go. The JS api is definitely simpler in many ways, but I am so much more proficient in C# that I am inclined to go that route. However, part of me thinks I should use this as an opportunity to finally become the last programmer on Earth to learn JavaScript! :grinning:

Tom