Erlang connect by external ip address
I write simple server application in erlang.
Code of this application: https://gist.github.com/783117
I try to connect to it with telnet. When I connect to localhost or local ip addres which get from route it's ok, but when i try to connect to server with external ip it's don't work.
What's wrong?
If i use options with {0,0,0,0}:
Opts = [binary, {ip, 0,0,0,0}, {reuseaddr, true},
{keepalive, false}, {a开发者_如何学运维ctive, false}],
I get:
exception exit: badarg
netstat -ltn | grep 110
tcp 0 0 0.0.0.0:110 0.0.0.0:* LISTEN
route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.1.0 0.0.0.0 255.255.255.0 U 202 0 0 eth0
0.0.0.0 192.168.1.1 0.0.0.0 UG 202 0 0 eth0
Thank you.
From gen_tcp manual:
listen(Port, Options) -> {ok, ListenSocket} | {error, Reason}
...
Sets up a socket to listen on the port Port on the local host.
...
{ip, ip_address()}
If the host has several network interfaces, this option specifies which one to listen on.
I suppose your server listens only on the local host. That is, you can't connect using other addresses. You probably need to use the ip
option. Maybe it's possible to use INADDR_ANY somehow like in C but I don't know.
[edit]
It appeared that it listens on INADDR_ANY by default even without ip
option (thanks to I GIVE CRAP ANSWERS).
And I can connect from other machines with the original code shared by the author. However firewall is disabled on my machine
Instead of {ip, 0,0,0,0}, you should pass: {ip, {0,0,0,0}}. You passed a tuple having 5 elements, instead of a tuple of 2 elements.
精彩评论