NetworkHelper 类
提供网络操作相关的帮助方法。
继承成员
命名空间: Fantasy.Helper
程序集: Fantasy.Net.dll
语法
public static class NetworkHelper
方法
| 编辑本文 查看源代码ByteToSocketAddress(byte[], int, out SocketAddress)
将byre[]转换为SocketAddress
声明
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int ByteToSocketAddress(byte[] buffer, int offset, out SocketAddress socketAddress)
参数
类型 | 名称 | 描述 |
---|---|---|
byte[] | buffer | |
int | offset | |
SocketAddress | socketAddress |
返回
类型 | 描述 |
---|---|
int |
异常
类型 | 条件 |
---|---|
ArgumentNullException | |
ArgumentException | |
InvalidOperationException |
ByteToSocketAddress(ReadOnlyMemory<byte>, int, out SocketAddress)
将ReadOnlyMemory转换为SocketAddress
声明
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int ByteToSocketAddress(ReadOnlyMemory<byte> buffer, int offset, out SocketAddress socketAddress)
参数
类型 | 名称 | 描述 |
---|---|---|
ReadOnlyMemory<byte> | buffer | |
int | offset | |
SocketAddress | socketAddress |
返回
类型 | 描述 |
---|---|
int |
异常
类型 | 条件 |
---|---|
ArgumentException | |
InvalidOperationException |
Clone(EndPoint)
克隆一个IPEndPoint
声明
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static IPEndPoint Clone(this EndPoint endPoint)
参数
类型 | 名称 | 描述 |
---|---|---|
EndPoint | endPoint |
返回
类型 | 描述 |
---|---|
IPEndPoint |
GetAddressIPs()
获取本机所有网络适配器的IP地址。
声明
public static string[] GetAddressIPs()
返回
类型 | 描述 |
---|---|
string[] | IP地址数组。 |
GetIPEndPoint(SocketAddress)
根据SocketAddress获得IPEndPoint
声明
public static IPEndPoint GetIPEndPoint(this SocketAddress socketAddress)
参数
类型 | 名称 | 描述 |
---|---|---|
SocketAddress | socketAddress |
返回
类型 | 描述 |
---|---|
IPEndPoint |
异常
类型 | 条件 |
---|---|
NotSupportedException |
GetIPEndPoint(string)
根据字符串获取一个IPEndPoint
声明
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static IPEndPoint GetIPEndPoint(string address)
参数
类型 | 名称 | 描述 |
---|---|---|
string | address |
返回
类型 | 描述 |
---|---|
IPEndPoint |
IPEndPointEquals(EndPoint, IPEndPoint)
比较两个IPEndPoint是否相等
声明
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool IPEndPointEquals(this EndPoint endPoint, IPEndPoint ipEndPoint)
参数
类型 | 名称 | 描述 |
---|---|---|
EndPoint | endPoint | |
IPEndPoint | ipEndPoint |
返回
类型 | 描述 |
---|---|
bool |
IPEndPointEquals(IPEndPoint, IPEndPoint)
比较两个IPEndPoint是否相等
声明
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool IPEndPointEquals(this IPEndPoint endPoint, IPEndPoint ipEndPoint)
参数
类型 | 名称 | 描述 |
---|---|---|
IPEndPoint | endPoint | |
IPEndPoint | ipEndPoint |
返回
类型 | 描述 |
---|---|
bool |
IPEndPointToStr(IPEndPoint)
将 IPEndPoint 实例转换为字符串表示形式。
声明
public static string IPEndPointToStr(this IPEndPoint self)
参数
类型 | 名称 | 描述 |
---|---|---|
IPEndPoint | self | IPEndPoint 实例。 |
返回
类型 | 描述 |
---|---|
string | 表示 IPEndPoint 的字符串。 |
SetReceiveBufferToOSLimit(Socket, int, int)
将 Socket 接收缓冲区大小设置为操作系统限制。 尝试增加接收缓冲区大小的次数 = 默认 + 最大增加 100 MB。
声明
public static void SetReceiveBufferToOSLimit(this Socket socket, int stepSize = 1024, int attempts = 100000)
参数
类型 | 名称 | 描述 |
---|---|---|
Socket | socket | 要设置接收缓冲区大小的 Socket。 |
int | stepSize | 每次增加的步长大小。 |
int | attempts | 尝试增加缓冲区大小的次数。 |
SetSendBufferToOSLimit(Socket, int, int)
将 Socket 发送缓冲区大小设置为操作系统限制。 尝试增加发送缓冲区大小的次数 = 默认 + 最大增加 100 MB。
声明
public static void SetSendBufferToOSLimit(this Socket socket, int stepSize = 1024, int attempts = 100000)
参数
类型 | 名称 | 描述 |
---|---|---|
Socket | socket | 要设置发送缓冲区大小的 Socket。 |
int | stepSize | 每次增加的步长大小。 |
int | attempts | 尝试增加缓冲区大小的次数。 |
SetSioUdpConnReset(Socket)
针对 Windows 平台设置UDP连接重置选项。
声明
public static void SetSioUdpConnReset(this Socket socket)
参数
类型 | 名称 | 描述 |
---|---|---|
Socket | socket | 要设置选项的 Socket 实例。 |
SetSocketBufferToOsLimit(Socket)
将 Socket 缓冲区大小设置为操作系统限制。
声明
public static void SetSocketBufferToOsLimit(this Socket socket)
参数
类型 | 名称 | 描述 |
---|---|---|
Socket | socket | 要设置缓冲区大小的 Socket。 |
SocketAddressToByte(SocketAddress, byte[], int)
将SocketAddress写入到Byte[]中
声明
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void SocketAddressToByte(this SocketAddress socketAddress, byte[] buffer, int offset)
参数
类型 | 名称 | 描述 |
---|---|---|
SocketAddress | socketAddress | |
byte[] | buffer | |
int | offset |
ToIPEndPoint(string)
将地址字符串转换为 IPEndPoint 实例。
声明
public static IPEndPoint ToIPEndPoint(string address)
参数
类型 | 名称 | 描述 |
---|---|---|
string | address | 地址字符串,格式为 "主机名:端口号"。 |
返回
类型 | 描述 |
---|---|
IPEndPoint | IPEndPoint 实例。 |
ToIPEndPoint(string, int)
将主机名和端口号转换为 IPEndPoint 实例。
声明
public static IPEndPoint ToIPEndPoint(string host, int port)
参数
类型 | 名称 | 描述 |
---|---|---|
string | host | 主机名。 |
int | port | 端口号。 |
返回
类型 | 描述 |
---|---|
IPEndPoint | IPEndPoint 实例。 |