Class P2pServerAsync
Namespace: Tool.Sockets.P2PHelpr
Assembly: Tool.Net.dll
开放用于P2P模块化的支持类 可以获取免费开放的打洞公网服务器支持
public sealed class P2pServerAsync : IDisposableInheritance
Implements
Inherited Members
object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.ReferenceEquals(object?, object?), object.ToString()
Extension Methods
ObjectExtension.Add<T>(object, object, object), ObjectExtension.CopyEntity(object, object, params string[]), ObjectExtension.EntityToJson(object), ObjectExtension.EntityToJson(object, bool), ObjectExtension.EntityToJson(object, bool, string), DictionaryExtension.GetDictionary(object), TypeExtension.GetFieldKey(object, string, out bool), TypeExtension.GetFieldKey<T>(object, string, out bool), TypeExtension.GetFieldKey(object, Type, string, out bool), ObjectExtension.GetIntPtr(object), ObjectExtension.GetIntPtrInt(object), TypeExtension.GetPropertieFind(object, string, bool), TypeExtension.GetProperties(object), TypeExtension.GetPropertyKey(object, string, out bool), TypeExtension.GetPropertyKey<T>(object, string, out bool), TypeExtension.GetPropertyKey(object, Type, string, out bool), TypeExtension.GetValue(object, PropertyDescriptor), TypeExtension.GetValue(object, string, bool), TypeExtension.GetValue(object, string), ObjectExtension.Read<T>(object, object, int, int), ObjectExtension.Read<T>(object, int, object, int, int), DictionaryExtension.SetDictionary(object, IDictionary<string, object>), TypeExtension.SetFieldKey(object, string, object), TypeExtension.SetFieldKey<T>(object, string, object), TypeExtension.SetFieldKey(object, Type, string, object), TypeExtension.SetPropertyKey(object, string, object), TypeExtension.SetPropertyKey<T>(object, string, object), TypeExtension.SetPropertyKey(object, Type, string, object), TypeExtension.SetValue(object, PropertyDescriptor, object), TypeExtension.SetValue(object, string, object, bool), TypeExtension.SetValue(object, string, object), ObjectExtension.ToBase64String(object), ObjectExtension.ToBytes(object), ObjectExtension.ToBytes(object, out Type), DictionaryExtension.ToDictionary(object), DictionaryExtension.ToDictionary<T>(object), DictionaryExtension.ToIDictionary(object), DictionaryExtension.ToIDictionary<T>(object), ObjectExtension.ToJson(object), ObjectExtension.ToJson(object, JsonSerializerOptions), ObjectExtension.ToJsonWeb(object), ObjectExtension.ToJsonWeb(object, Action<JsonSerializerOptions>), ObjectExtension.ToTryVar<T>(object, T), ObjectExtension.ToVar<T>(object), ObjectExtension.ToVar(object, Type, bool), ObjectExtension.ToVar(object, string), ObjectExtension.ToXml(object)
Properties
LocalEP
用于本地绑定的IP:Port
public Ipv4Port LocalEP { get; }Property Value
Millisecond
设置连接服务器超时时间
public int Millisecond { get; init; }Property Value
RemoteEP
用于P2P绑定的IP:Port
public Ipv4Port RemoteEP { get; }Property Value
TcpTop
TCP验证头
public static Memory<byte> TcpTop { get; }Property Value
UdpTop
UDP验证头
public static Memory<byte> UdpTop { get; }Property Value
Methods
Dispose()
回收相关资源
public void Dispose()GetFree(IPEndPoint, bool)
用于获取私有P2PServer服务器的通信消息
public static ValueTask<P2pServerAsync> GetFree(IPEndPoint endPoint, bool isTcp)Parameters
endPoint IPEndPoint
服务器IP端口
isTcp bool
获取的P2P类型
Returns
成功后的结果
GetFreeTcp()
获取公共的P2PServer服务器的通信消息 TCP版本
public static ValueTask<P2pServerAsync> GetFreeTcp()Returns
成功后的结果
GetFreeUdp()
获取公共的P2PServer服务器的通信消息 UDP版本
public static ValueTask<P2pServerAsync> GetFreeUdp()Returns
成功后的结果
IsP2pAuth(Span<byte>, out Ipv4Port)
验证一个数据流,确定它是否是符合协议的P2P(发起)协议
public static bool IsP2pAuth(Span<byte> span, out Ipv4Port localEP)Parameters
localEP Ipv4Port
Returns
IsP2pWait(Span<byte>, out Ipv4Port)
验证一个数据流,确定它是否是符合协议的P2P(等待)协议
public static bool IsP2pWait(Span<byte> span, out Ipv4Port localEP)Parameters
localEP Ipv4Port
Returns
IsSuccess()
判断是否P2P是否可用
public bool IsSuccess()Returns
OkWait(CancellationToken)
判断是否通过双方等待验证
public bool OkWait(CancellationToken token)Parameters
token CancellationToken
Returns
P2PConnectAsync(TcpClientAsync, Ipv4Port, int)
尝试发起P2P连接,通过服务器验证确保可以更可靠的完成连接
public Task P2PConnectAsync(TcpClientAsync clientAsync, Ipv4Port RemoteEP, int timedDelay = 5000)Parameters
clientAsync TcpClientAsync
要建立连接的对象
RemoteEP Ipv4Port
连接的对方设备
timedDelay int
尝试等待超时时间(不能小于1000ms)
Returns
结果
Exceptions
不可用 或 模式不一致 或 超时!
P2PConnectAsync(UdpClientAsync, Ipv4Port, int)
尝试发起P2P连接,通过服务器验证确保可以更可靠的完成连接
public Task P2PConnectAsync(UdpClientAsync clientAsync, Ipv4Port RemoteEP, int timedDelay = 5000)Parameters
clientAsync UdpClientAsync
要建立连接的对象
RemoteEP Ipv4Port
连接的对方设备
timedDelay int
尝试等待超时时间(不能小于1000ms)
Returns
结果
Exceptions
不可用 或 模式不一致 或 超时!