vshesh

vshesh

:gen_tcp doesn't work even though netcat does?

I’m running the fluidsynth server and want to send noteon events from elixir to the fluidsynth process.
I can do

$ nc localhost 8000
> noteon 0 40 100

And I hear a sound being played… when I use :gen_tcp I do not see the same results:

iex(10)> {:ok, sock} = :gen_tcp.connect({127,0,0,1}, 8000, [:binary, active: true])
{:ok, #Port<0.7>}
iex(11)> :gen_tcp.send(sock, "noteon 0 40 100")
:ok

… nothing gets played though. I’m guessing I have some option incorrect? I need to use something other than :binary maybe since these are plain strings?

Marked As Solved

jarimatti

jarimatti

Does the protocol expect lines that are separated by newline \n? Netcat sends the newline character over (if you press enter) and the Elixir code sends the string but not the newline.

Does sending "noteon 0 40 100\n" from Elixir work? That’s one difference I can think of.

If you need to receive line-based data see also the Erlang docs for inet:setopts, specifically {packet, line}. It only applies to received packets.

Also Liked

proxima

proxima

Without knowing anything about fluidsynth, that looks like it might be a line-based tcp protocol given the lack of size headers or the like.

Have you tried adding a ‘\n’ or ‘\r\n’ to the end? Netcat is probably sending them implicitly as you press enter.

Where Next?

Popular in Questions Top

Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
LegitStack
I’m hoping you guys can give me some general advice and perhaps code examples if you’re feeling up to it. I’m very interested in Elixir,...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
Codball
Mix format works fine if run from the cmd. I’ve followed this to facilitate the implementation into VSC which involves downloading an ext...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New

Other popular topics Top

vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 49522 488
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod -- where is this set? Thanks.
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

We're in Beta

About us Mission Statement