I can talk to TCP from netcat, but not from :gen_tcp - why?

How can I connect to a TCP endpoint using Elixir?

I have Vowpal Wabbit server running at a certain IP and on a certain port. I can interact with it from the command line as follows:

echo "|c country_US" | nc 10.228.14.116 26542
0.512143    <-- this is the response

On the other hand, if I don’t pipe any info to netcat, it behaves as follows:

nc 10.228.14.116 26542  <-- just waits forever

This is expected and correct behavior for my Vowpal Wabbit setup. Now I just need to talk to Vowpal Wabbit via TCP from Elixir.

From within IEX:

opts = [:binary, active: false]
{:ok, socket} = :gen_tcp.connect({10, 228, 14, 116}, 26542, opts)
** (MatchError) no match of right hand side value: {:error, :etimedout} 

So my question is: Given that my service is running correctly and responding on TCP, how can I connect to it using :gen_tcp?

Thanks.

As far as I can see, there is nothing wrong with your code. Have you used tcpdump/wireshark to analyze the differences between those connections?

2 Likes

Thanks for the tcpdump suggestion – I did make use of it. Turns out that the IP address I’m trying to reach requires me to be on a certain VPN and I must also have had a typo in my code at some point. So I think I was running the right code on the wrong VPN for a while and then code with a typo while on the right VPN. Eventually I sorted it all out…

3 Likes