@@ -36,6 +36,7 @@ public class JsonRpcHttpServer : IDisposable
36
36
public string [ ] ServerAddresses => _serverAddressFeature ( ) . Addresses . ToArray ( ) ;
37
37
38
38
public int ServerPort => GetServerPort ( ) ;
39
+ public Uri ServerAddress => GetServerHostAddress ( ) ;
39
40
40
41
Func < IServerAddressesFeature > _serverAddressFeature ;
41
42
IRpcController _serverHandler ;
@@ -55,7 +56,7 @@ public RpcRequestItem(JObject requestMessage)
55
56
56
57
57
58
/// <param name="port">If null or unspecified the http server binds to a random port.</param>
58
- public JsonRpcHttpServer ( IRpcController serverHandler , Func < IWebHostBuilder , IWebHostBuilder > configure = null , int ? port = null )
59
+ public JsonRpcHttpServer ( IRpcController serverHandler , Func < IWebHostBuilder , IWebHostBuilder > configure = null , int ? port = null , IPAddress address = null )
59
60
{
60
61
_serverHandler = serverHandler ;
61
62
var webHostBuilder = new WebHostBuilder ( )
@@ -68,7 +69,7 @@ public JsonRpcHttpServer(IRpcController serverHandler, Func<IWebHostBuilder, IWe
68
69
. UseSockets ( )
69
70
. UseKestrel ( options =>
70
71
{
71
- options . Listen ( IPAddress . Loopback , port ?? 0 ) ;
72
+ options . Listen ( address ?? IPAddress . Loopback , port ?? 0 ) ;
72
73
//options.Listen(port ?? 0);
73
74
} ) ;
74
75
@@ -99,8 +100,7 @@ public JsonRpcHttpServer(IRpcController serverHandler, Func<IWebHostBuilder, IWe
99
100
100
101
public void Stop ( ) => WebHost . StopAsync ( ) . GetAwaiter ( ) . GetResult ( ) ;
101
102
102
-
103
- int GetServerPort ( )
103
+ Uri GetServerHostAddress ( )
104
104
{
105
105
var addrs = ServerAddresses ;
106
106
if ( addrs . Length == 0 )
@@ -109,9 +109,12 @@ int GetServerPort()
109
109
}
110
110
111
111
var httpAddr = addrs . FirstOrDefault ( addr => addr . StartsWith ( "http://" , StringComparison . OrdinalIgnoreCase ) ) ;
112
- var addrParts = httpAddr . Split ( ':' ) [ 2 ] ;
113
- var port = int . Parse ( addrParts , CultureInfo . InvariantCulture ) ;
114
- return port ;
112
+ return new Uri ( httpAddr ) ;
113
+ }
114
+
115
+ int GetServerPort ( )
116
+ {
117
+ return GetServerHostAddress ( ) . Port ;
115
118
}
116
119
117
120
async Task Handle ( HttpContext context , Func < Task > next )
0 commit comments