hubertlepicki

hubertlepicki

I am trying to build something using Phoenix channels, and as great as they are, I am hitting a wall with something.

Basically, I need to send data to server in “fire and forget” manner. I may also get occasional messages from the server. I am not interested in retries, failures, and correct order of arrival of my (or server’s) messages.

I need a UDP-like connection, and Phoenix channels are TCP-like.

I know WebRTC data channels can be put into “unreliable” mode. This looks like what I need precisely, and I tested it browser-to-browser, this will be alright.

But I failed to find any info on how can I integrate that with Elixir on the server. Any ideas?

It’s not a signaling server I need, but a server that would join WebRTC data channel in similar fashion as browsers do.

Showing Posts 1 to 10

shavit

shavit

I’m working on a media server that accept UDP using Elixir.

The route that accept the connection is here:
https://github.com/shavit/Diana/blob/master/lib/video_chat/incoming_stream.ex#L16

You are probably looking for this line:
{:ok, _socket} = :gen_udp.open(3001, [:binary, {:active, true}])

Test it:

echo "---> Streaming video ${MEDIA_FILE} at ${FRAMERATE} to the server"
ffmpeg \
  -i $MEDIA_FILE \
  -c:a aac -ar 44100 -ab 128k -ac 2 -strict -2 -c:v libx264 -vb 500k \
  -r $FRAMERATE -s 640x480 -ss 00.000 -f avi \
  udp://127.0.0.1:3001
michalmuskala

michalmuskala

AFAIK there’s nothing in the phoenix channels that require it to be backed by TCP. It’s only at the transport level (handled by the Phoenix.Socket.Transport behaviour), where the semantics are established. It’s true that both of the built-in transport implementations - websockets and longpoll - are tcp-based. But it’s not impossible to have a custom transport backed by raw udp, WebRTC or other solutions that do not have retry semantics.

sasajuric

sasajuric

Author of Elixir In Action

I’m not sure if using Phoenix for accepting UDP makes sense. Phoenix endpoint is powered by Cowboy, so TCP is always underneath. UDP is connectionless, so even if it can somehow be integrated directly into endpoint, I think it would be a needless complication.

If the system needs to handle UDP next to TCP traffic, I’d just start a separate process powered by gen_udp. I think it can even listen on the same port as the endpoint, as the networking protocols are different.

hubertlepicki

hubertlepicki OP

I was thinking the same, this probably should not be part of the Phoenix pipeline. And @michalmuskala I do not think I need any of the Phoenix channel connection handling mechanisms either. I don’ t need nor want connection established/dropped events, since there’s really no connection involved. All I want is to send and receive messages, as quickly as possible to reduce the latency.

I think I’ll start off by inspecting how WebRTC DataChannel works when two browsers are connected. Wireshark should do the job I think. I imagine this being pretty thin layer over UDP, but let’s see.

I was trying to check if someone did such thing already possibly in Erlang so I don’t have to do all the hard work :wink:

michalmuskala

michalmuskala

@hubertlepicki While it might be possible to do this with phoenix, it might not be the best idea - I forgot to add that to my response :smirk: So I fully agree with you here.

@sasajuric I don’t think the channel has to be started by the cowboy. The transport implementation controls this entirely.

gregvaughn

gregvaughn

I’m not familiar enough with the details to offer much help, but I wanted to make sure you were aware of this conference talk which seems relevant

shavit

shavit

So why using WebRTC and not UDP which is much simpler and faster? Handshake will slow down the connection.

hubertlepicki

hubertlepicki OP

Oh, I wasn’t aware that there is some other way to use UDP directly from browser… I know you can do it using browser extension, but I do not think I can normally from web pages… Can I do it somehow?

shavit

shavit

I didn’t saw that you were looking for a browser solution. I was broadcasting using native apps.

Yes, there is the native (WebRTC) getUserMedia with limited browser support, and also ActionScript that requires Flash player installed.

sasajuric

sasajuric

Author of Elixir In Action

You’re actually right that a socket can be driven separately, I’ve even blogged about it here. So I guess that Phoenix sockets could be driven through gen_udp. Some uncertainty remains, for example how does the lack of guarantees on message arrival and ordering affect socket/channels semantics, but the idea seems interesting.

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews