-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for setting port 0 on passive tcp/ip channels
- Loading branch information
1 parent
c90ae0a
commit 95d0820
Showing
5 changed files
with
45 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Net; | ||
using System.Net.Sockets; | ||
using System.Runtime.InteropServices.ComTypes; | ||
using System.Text; | ||
|
||
namespace MessageCommunicator.Tests.Util | ||
{ | ||
internal static class TestUtility | ||
{ | ||
public static ushort GetFreeTcpPort() | ||
{ | ||
// Simple method do find a free port | ||
// see https://stackoverflow.com/questions/138043/find-the-next-tcp-port-in-net | ||
|
||
var dummyListener = new TcpListener(IPAddress.Loopback, 0); | ||
|
||
dummyListener.Start(); | ||
var port = (ushort)((IPEndPoint)dummyListener.LocalEndpoint).Port; | ||
dummyListener.Stop(); | ||
|
||
return port; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters