I use Erlang to encode the bittorrent client. I’ve been stuck for 4 days on the same issue.
I send a handshake to all my peers, each of whom has his own ip: port.
I am using gen_tcp: connect to connect.
The problem is that I cannot get an answer. I did a lot of research and used some programs to monitor incoming / outgoing connections.
Peers receive data and send a response back to the port that I used to send them a handshake.
The wise: get_tcp: connect code selects a port and uses this port to send data to the peer. The response friend responds to this port. However, as you know, in Erlang you need to use gen_tcp: listen to get a response connection, and you need to specify a port. In my case, the port I should listen on is the port that gen_tcp: connect is returning.
I can get this port number using inet: port, but the error is always the same: the port used. I understand why I am getting the error, simply because the port I'm trying to listen to is already using gen_tcp: connect. I tried closing Socket to free the port, but nothing.
So my question is: is it possible in Erlang to somehow connect to a peer and send data to it in a port, and then listen to the same port for an answer. If not, I must somehow tell the partner to send me the data back to the port that I choose.
Any ideas from all the gurus of Erlang are welcome. Thank,
//Franc.
Frank source
share