Skip to content

Commit 82a6ef6

Browse files
committed
Update Endpoint to handle automatically assigned ports
1 parent 60851da commit 82a6ef6

3 files changed

Lines changed: 6 additions & 0 deletions

File tree

source/NetCoreServer/SslServer.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ public virtual bool Start()
145145

146146
// Bind the acceptor socket to the IP endpoint
147147
_acceptorSocket.Bind(Endpoint);
148+
// Refresh the endpoint property based on the actual endpoint created
149+
Endpoint = (IPEndPoint)_acceptorSocket.LocalEndPoint;
148150
// Start listen to the acceptor socket with the given accepting backlog size
149151
_acceptorSocket.Listen(_acceptorBacklog);
150152

source/NetCoreServer/TcpServer.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ public virtual bool Start()
136136

137137
// Bind the acceptor socket to the IP endpoint
138138
_acceptorSocket.Bind(Endpoint);
139+
// Refresh the endpoint property based on the actual endpoint created
140+
Endpoint = (IPEndPoint)_acceptorSocket.LocalEndPoint;
139141
// Start listen to the acceptor socket with the given accepting backlog size
140142
_acceptorSocket.Listen(_acceptorBacklog);
141143

source/NetCoreServer/UdpServer.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ public virtual bool Start()
150150

151151
// Bind the server socket to the IP endpoint
152152
Socket.Bind(Endpoint);
153+
// Refresh the endpoint property based on the actual endpoint created
154+
Endpoint = (IPEndPoint)Socket.LocalEndPoint;
153155

154156
// Prepare receive endpoint
155157
_receiveEndpoint = new IPEndPoint((Endpoint.AddressFamily == AddressFamily.InterNetworkV6) ? IPAddress.IPv6Any : IPAddress.Any, 0);

0 commit comments

Comments
 (0)