@@ -38,8 +38,8 @@ private void OnApplicationPause(bool pause)
3838 return ;
3939 if ( pause )
4040 {
41- Socket . Close ( true ) ;
4241 Paused = true ;
42+ Socket . Close ( true ) ;
4343 }
4444 else if ( Paused )
4545 {
@@ -48,7 +48,6 @@ private void OnApplicationPause(bool pause)
4848 NetDebug . WriteError ( "[S] Cannot restore connection \" {0}\" ,\" {1}\" port {2}" , BindAddrIPv4 , BindAddrIPv6 , Port ) ;
4949 Socket . OnErrorRestore ( ) ;
5050 }
51- Paused = false ;
5251 }
5352 }
5453 }
@@ -198,6 +197,9 @@ public bool Bind(IPAddress addressIPv4, IPAddress addressIPv6, int port, bool re
198197
199198 if ( ! BindSocket ( _udpSocketv4 , new IPEndPoint ( dualMode ? addressIPv6 : addressIPv4 , port ) , reuseAddress , ipv6Mode ) )
200199 return false ;
200+
201+ LocalPort = ( ( IPEndPoint ) _udpSocketv4 . LocalEndPoint ) . Port ;
202+
201203#if UNITY_IOS && ! UNITY_EDITOR
202204 if ( _unitySocketFix == null )
203205 {
@@ -208,14 +210,17 @@ public bool Bind(IPAddress addressIPv4, IPAddress addressIPv6, int port, bool re
208210 _unitySocketFix . BindAddrIPv4 = addressIPv4 ;
209211 _unitySocketFix . BindAddrIPv6 = addressIPv6 ;
210212 _unitySocketFix . Reuse = reuseAddress ;
211- _unitySocketFix . Port = port ;
213+ _unitySocketFix . Port = LocalPort ;
212214 _unitySocketFix . IPv6 = ipv6Mode ;
213215 }
216+ else
217+ {
218+ _unitySocketFix . Paused = false ;
219+ }
214220#endif
215221 if ( dualMode )
216222 _udpSocketv6 = _udpSocketv4 ;
217223
218- LocalPort = ( ( IPEndPoint ) _udpSocketv4 . LocalEndPoint ) . Port ;
219224 IsRunning = true ;
220225 _threadv4 = new Thread ( ReceiveLogic )
221226 {
0 commit comments