Skip to content

Commit be5f656

Browse files
authored
Merge pull request #12 from olehs/patch-1
2 parents c72dd71 + 0de2f7b commit be5f656

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

android/src/main/java/com/peel/react/TcpSocketManager.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,19 @@ public void listen(final Integer cId, final String host, final Integer port) thr
8181
}
8282

8383
mServer.listen(InetAddress.getByName(host), port, new ListenCallback() {
84+
InetSocketAddress localAddress = socketAddress;
85+
8486
@Override
8587
public void onListening(AsyncServerSocket socket) {
8688
mClients.put(cId, socket);
8789

90+
if(socketAddress.getPort() != socket.getLocalPort()) {
91+
localAddress = new InetSocketAddress(socketAddress.getAddress(), socket.getLocalPort());
92+
}
93+
8894
TcpSocketListener listener = mListener.get();
8995
if (listener != null) {
90-
listener.onConnect(cId, socketAddress);
96+
listener.onConnect(cId, localAddress);
9197
}
9298
}
9399

@@ -97,7 +103,7 @@ public void onAccepted(AsyncSocket socket) {
97103
mClients.put(mInstances, socket);
98104

99105
AsyncNetworkSocket socketConverted = Util.getWrappedSocket(socket, AsyncNetworkSocket.class);
100-
InetSocketAddress remoteAddress = socketConverted != null ? socketConverted.getRemoteAddress() : socketAddress;
106+
InetSocketAddress remoteAddress = socketConverted != null ? socketConverted.getRemoteAddress() : localAddress;
101107

102108
TcpSocketListener listener = mListener.get();
103109
if (listener != null) {

0 commit comments

Comments
 (0)