Allow client to bind on a random port
This commit is contained in:
parent
bba56fc988
commit
4efe081084
1 changed files with 25 additions and 13 deletions
|
@ -53,6 +53,17 @@ void CSocket::Init ( const quint16 iPortNumber )
|
|||
bool bSuccess;
|
||||
|
||||
if ( bIsClient )
|
||||
{
|
||||
if (iPortNumber == 0)
|
||||
{
|
||||
// If port number is 0, bind the client to a random available port.
|
||||
UdpSocketInAddr.sin_port = htons ( iPortNumber );
|
||||
|
||||
bSuccess = ( ::bind ( UdpSocket ,
|
||||
(sockaddr*) &UdpSocketInAddr,
|
||||
sizeof ( sockaddr_in ) ) == 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
// Per definition use the port number plus ten for the client to make
|
||||
// it possible to run server and client on the same computer. If the
|
||||
|
@ -73,6 +84,7 @@ void CSocket::Init ( const quint16 iPortNumber )
|
|||
iClientPortIncrement++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// for the server, only try the given port number and do not try out
|
||||
|
|
Loading…
Reference in a new issue