Elixir TCP Broadcast and .Net Reflection

Hello everybody!

I want to know if there is any example to make broadcast of tcp sockets, with rooms (like channels on phoenix but in tcp and its own protocol) and pub/sub, I just have see some examples with tcp but can’t broadcast to many etc…

Also… In .Net c# we have something called reflection, basically I use it to call dynamically methods, an example…

[TestAttribute(256)]
public static void Method256(Socket client, Message message) {
    client.Send(new SomeMessage(message.data);
}

[TestAttribute(257)]
public static void Method257(Socket client, Message message)....

With this I can create a function that parse all the TestAttributes in the program with the respective value of the attribute, and I can call at any time this method giving the attribute id and the client and message as parameter…

It’s possible to do something like this on elixir? Call function based on identifiers? Or I need to do it manually?

Thanks ^.^

That’s because TCP is strictly unicast - so a “broadcaster” has to go through the list of clients and dispatch the message to each in turn.

.NET languages are typically statically typed so there is more information available at runtime. But Module.__info__/1 can give you a list of functions and if you know what arguments to provide (… though how would you, all you have is the arity …) you can use Kernel.apply/3 to invoke the function dynamically (the function name is provided as an atom).

Thanks for the answer

Oh right, yeah I was forgoting it, but I havent see any example for it on Elixir sadly

In there a way to parse all program to get every module info? also to call the apply function I need to do something like this right?

apply(Module.__info__(:module), :method, [args])
iex> Kernel.apply IO, :puts, ["Hello"]
Hello
:ok
iex>

Yeah but… For example I can have 2000 modules, I need a way to get “IO” equivalent of every module dynamically and pass it as argument on Kerner.apply

This is how iex does it using the Erlang :code module.

1 Like

All right so many thanks :smiley: