Websocket server without Phoenix

Hi All…

I’m working on an embedded project that will collect data from a system of sensors, do some minimal processing and, among other things, stream data to a number of devices including phones, tablets and laptops. For this last requirement I was thinking WiFi and websockets. What I don’t need, however, is an entire framework.

I was reading about this:

But I’m wondering, could that be enough to implement websocket connectivity to a number of clients? It could work as peer to peer. At the device end (my device) I was thinking there would be a process to handle each connected client and each of these would periodically push data through the socket.

I’m just trying to avoid extra complexity and bloat.

Suggestions are appreciated, thank you.

Why do you need websockets? I think of them as “tcp for browsers.” Wouldn’t something like mqtt or plain tcp suit your needs better?

1 Like

Hm, I’m not sure. The clients are going to be single page web apps. The thought was to stream JSON data in via websocket and render it.

Ah, ok. This bit got me confused

number of devices including phones, tablets and laptops

Thought you would use their native tcp/ip stack.

You can use cowboy without phoenix. It has enough functionality to serve as a websocket server.

That does seem to be what I need, thanks!

Cowboy has websocket support built in, and you can use Plug to make a clean interface. I’ve still yet to jump into Phoenix and this works great for me.

Here’ some sample code, https://github.com/NationalAssociationOfRealtors/BoothNanoleaf/blob/master/lib/booth_nanoleaf/application.ex

1 Like

Excellent thank you! I got Cowboy working last night, websockets are next on the list.