@@ -303,9 +303,9 @@ public struct ConnectionAddressData
303303 public ushort Port ;
304304
305305 /// <summary>
306- /// IP address the server will listen on. If not provided, will use 'Address' .
306+ /// IP address the server will listen on. If not provided, will use 0.0.0.0 .
307307 /// </summary>
308- [ Tooltip ( "IP address the server will listen on. If not provided, will use 'Address' ." ) ]
308+ [ Tooltip ( "IP address the server will listen on. If not provided, will use 0.0.0.0 ." ) ]
309309 [ SerializeField ]
310310 public string ServerListenAddress ;
311311
@@ -330,7 +330,29 @@ private static NetworkEndpoint ParseNetworkEndpoint(string ip, ushort port)
330330 /// <summary>
331331 /// Endpoint (IP address and port) server will listen/bind on.
332332 /// </summary>
333- public NetworkEndpoint ListenEndPoint => ParseNetworkEndpoint ( ( ServerListenAddress ? . Length == 0 ) ? Address : ServerListenAddress , Port ) ;
333+ public NetworkEndpoint ListenEndPoint
334+ {
335+ get
336+ {
337+ if ( string . IsNullOrEmpty ( ServerListenAddress ) )
338+ {
339+ var ep = NetworkEndpoint . AnyIpv4 ;
340+
341+ // If an address was entered and it's IPv6, switch to using :: as the
342+ // default listen address. (Otherwise we always assume IPv4.)
343+ if ( ! string . IsNullOrEmpty ( Address ) && ServerEndPoint . Family == NetworkFamily . Ipv6 )
344+ {
345+ ep = NetworkEndpoint . AnyIpv6 ;
346+ }
347+
348+ return ep . WithPort ( Port ) ;
349+ }
350+ else
351+ {
352+ return ParseNetworkEndpoint ( ServerListenAddress , Port ) ;
353+ }
354+ }
355+ }
334356 }
335357
336358 /// <summary>
@@ -529,14 +551,14 @@ private bool ServerBindAndListen(NetworkEndpoint endPoint)
529551 int result = m_Driver . Bind ( endPoint ) ;
530552 if ( result != 0 )
531553 {
532- Debug . LogError ( "Server failed to bind" ) ;
554+ Debug . LogError ( "Server failed to bind. This is usually caused by another process being bound to the same port. " ) ;
533555 return false ;
534556 }
535557
536558 result = m_Driver . Listen ( ) ;
537559 if ( result != 0 )
538560 {
539- Debug . LogError ( "Server failed to listen" ) ;
561+ Debug . LogError ( "Server failed to listen. " ) ;
540562 return false ;
541563 }
542564
@@ -1473,7 +1495,7 @@ public void CreateDriver(UnityTransport transport, out NetworkDriver driver,
14731495 {
14741496 if ( NetworkManager . IsServer )
14751497 {
1476- if ( String . IsNullOrEmpty ( m_ServerCertificate ) || String . IsNullOrEmpty ( m_ServerPrivateKey ) )
1498+ if ( string . IsNullOrEmpty ( m_ServerCertificate ) || string . IsNullOrEmpty ( m_ServerPrivateKey ) )
14771499 {
14781500 throw new Exception ( "In order to use encrypted communications, when hosting, you must set the server certificate and key." ) ;
14791501 }
@@ -1482,11 +1504,11 @@ public void CreateDriver(UnityTransport transport, out NetworkDriver driver,
14821504 }
14831505 else
14841506 {
1485- if ( String . IsNullOrEmpty ( m_ServerCommonName ) )
1507+ if ( string . IsNullOrEmpty ( m_ServerCommonName ) )
14861508 {
14871509 throw new Exception ( "In order to use encrypted communications, clients must set the server common name." ) ;
14881510 }
1489- else if ( String . IsNullOrEmpty ( m_ClientCaCertificate ) )
1511+ else if ( string . IsNullOrEmpty ( m_ClientCaCertificate ) )
14901512 {
14911513 m_NetworkSettings . WithSecureClientParameters ( m_ServerCommonName ) ;
14921514 }
0 commit comments