We create 2 connections between Java server and C++ client. The Java ServerSocket object call accept() twice and each returns 1 socket; the C++ client call connect() twice. We assume the port of the 1st Socket returned by accept() should be the same as the port of the first client socket calling connect(), and same for 2nd pair sockets.
But by examine the port number on each socket, I have seen the abnormal case occasionally, in which the 1st Socket from accept() connect to 2nd client socket calling connect(), and 2nd socket from accept() connect to the 1st client socket.
Both server and client are single threaded here for establishing connection. How can the sequence be reversed ?