Dreamine.Communication.Sockets 1.0.2
Dreamine.Communication.Sockets 통신 기능과 관련 API를 제공합니다.
로딩중...
검색중...
일치하는것 없음
UdpTransportOptions.cs
이 파일의 문서화 페이지로 가기
1using System.Net;
2
4
13public sealed class UdpTransportOptions
14{
23 public string LocalHost { get; set; } = "127.0.0.1";
24
33 public int LocalPort { get; set; } = 16001;
34
43 public string RemoteHost { get; set; } = "127.0.0.1";
44
53 public int RemotePort { get; set; } = 16002;
54
63 public int ReceiveBufferSize { get; set; } = 8192;
64
73 public int SendBufferSize { get; set; } = 8192;
74
83 public bool EnableBroadcast { get; set; }
84
93 public bool ReuseAddress { get; set; }
94
111 public IPEndPoint CreateLocalEndPoint()
112 {
113 return new IPEndPoint(ParseHost(LocalHost, allowAny: true), LocalPort);
114 }
115
132 public IPEndPoint CreateRemoteEndPoint()
133 {
134 return new IPEndPoint(ParseHost(RemoteHost, allowAny: false), RemotePort);
135 }
136
177 private static IPAddress ParseHost(string host, bool allowAny)
178 {
179 ArgumentException.ThrowIfNullOrWhiteSpace(host);
180
181 if (allowAny && host == "0.0.0.0")
182 {
183 return IPAddress.Any;
184 }
185
186 if (host == "127.0.0.1" ||
187 host.Equals("localhost", StringComparison.OrdinalIgnoreCase))
188 {
189 return IPAddress.Loopback;
190 }
191
192 if (IPAddress.TryParse(host, out var ipAddress))
193 {
194 return ipAddress;
195 }
196
197 throw new ArgumentException($"Invalid UDP host: {host}", nameof(host));
198 }
199}
static IPAddress ParseHost(string host, bool allowAny)