Horizon – Blame information for rev 12
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
12 | office | 1 | using System; |
2 | using System.Collections.Generic; |
||
3 | using System.Linq; |
||
4 | using System.Net.Sockets; |
||
5 | using System.Net; |
||
6 | using System.Text; |
||
7 | using System.Threading.Tasks; |
||
8 | |||
9 | namespace Horizon.Utilities.Networking |
||
10 | { |
||
11 | public static class Miscellaneous |
||
12 | { |
||
13 | private static readonly IPEndPoint DefaultLoopbackEndpoint = new IPEndPoint(IPAddress.Loopback, port: 0); |
||
14 | |||
15 | public static ushort GetAvailableTcpPort() |
||
16 | { |
||
17 | using var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); |
||
18 | |||
19 | socket.Bind(DefaultLoopbackEndpoint); |
||
20 | var port = ushort.Parse($"{((IPEndPoint)socket.LocalEndPoint).Port}"); |
||
21 | return port; |
||
22 | } |
||
23 | } |
||
24 | } |