Rapsssito / react-native-tcp-socket

React Native TCP socket API for Android, iOS & macOS with SSL/TLS support.
MIT License
315 stars 82 forks source link

Second socket cannot connect #25

Closed deiv23 closed 4 years ago

deiv23 commented 4 years ago

Hi, I have no problems establishing a connection for the first time. But after that first connection, I want to establish a new connection on the same port and ip, and the server socket (written in python) gets stuck on accept for this second connection.

Here is my code:

let options = {port:4444, host:self.props.ip, reuseAddress:true, localAddress:this.ipAddress, localPort:4444};
var options2 = {port:4444, host:self.props.ip, reuseAddress:true, localAddress:this.ipAddress, localPort:4444};

var client = TcpSocket.createConnection(options);
client.on('error', function(error) {
     console.log("error1->" + error);
});
client.write('config-' + this.ipAddress); // I receive this on the server side succesfully
client.destroy();

var client2= TcpSocket.createConnection(options2);  //this call does not trigger the accept on the server side
Rapsssito commented 4 years ago

Could you please test the code with a different server in order to determine if it is a client or server-side issue?

deiv23 commented 4 years ago

I use same server with another app in react (not react-native), where I use 'net-socket' and it's working properly. Previously the server was on a windows machine, now I ported it to linux, I'll keep investigating to know if it is a server-side issue.

Rapsssito commented 4 years ago

@deiv23, looking at your code, it looks like you are creating both sockets on the same localAddress and localPort, that may be causing the second client to not bind correctly.

Please, try to change the second localPort to a different one.

deiv23 commented 4 years ago

Hi @Rapsssito , you were right, the problem was on the server. Now is working properly. Thanks!!

Rapsssito commented 4 years ago

Glad you fixed it!