@@ -1591,6 +1591,48 @@ public NetPeer Connect(IPEndPoint target, NetDataWriter connectionData)
15911591 }
15921592 }
15931593
1594+ #if LITENETLIB_SPANS || NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || NETCOREAPP2_1 || NETCOREAPP3_1 || NET5_0 || NETSTANDARD2_1
1595+ /// <summary>
1596+ /// Connect to remote host
1597+ /// </summary>
1598+ /// <param name="target">Server end point (ip and port)</param>
1599+ /// <param name="connectionData">Additional data for remote peer</param>
1600+ /// <returns>New NetPeer if new connection, Old NetPeer if already connected, null peer if there is ConnectionRequest awaiting</returns>
1601+ /// <exception cref="InvalidOperationException">Manager is not running. Call <see cref="Start()"/></exception>
1602+ public NetPeer Connect ( IPEndPoint target , ReadOnlySpan < byte > connectionData )
1603+ {
1604+ if ( ! _isRunning )
1605+ throw new InvalidOperationException ( "Client is not running" ) ;
1606+
1607+ lock ( _requestsDict )
1608+ {
1609+ if ( _requestsDict . ContainsKey ( target ) )
1610+ return null ;
1611+
1612+ byte connectionNumber = 0 ;
1613+ if ( TryGetPeer ( target , out var peer ) )
1614+ {
1615+ switch ( peer . ConnectionState )
1616+ {
1617+ //just return already connected peer
1618+ case ConnectionState . Connected :
1619+ case ConnectionState . Outgoing :
1620+ return peer ;
1621+ }
1622+ //else reconnect
1623+ connectionNumber = ( byte ) ( ( peer . ConnectionNum + 1 ) % NetConstants . MaxConnectionNumber ) ;
1624+ RemovePeer ( peer , true ) ;
1625+ }
1626+
1627+ //Create reliable connection
1628+ //And send connection request
1629+ peer = new NetPeer ( this , target , GetNextPeerId ( ) , connectionNumber , connectionData ) ;
1630+ AddPeer ( peer ) ;
1631+ return peer ;
1632+ }
1633+ }
1634+ #endif
1635+
15941636 /// <summary>
15951637 /// Force closes connection and stop all threads.
15961638 /// </summary>
0 commit comments