Skip to content

Class P2pServerAsync

Namespace: Tool.Sockets.P2PHelpr
Assembly: Tool.Net.dll

开放用于P2P模块化的支持类 可以获取免费开放的打洞公网服务器支持

csharp
public sealed class P2pServerAsync : IDisposable

Inheritance

objectP2pServerAsync

Implements

IDisposable

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

csharp
public Ipv4Port LocalEP { get; }

Property Value

Ipv4Port

Millisecond

设置连接服务器超时时间

csharp
public int Millisecond { get; init; }

Property Value

int

RemoteEP

用于P2P绑定的IP:Port

csharp
public Ipv4Port RemoteEP { get; }

Property Value

Ipv4Port

TcpTop

TCP验证头

csharp
public static Memory<byte> TcpTop { get; }

Property Value

Memory<byte>

UdpTop

UDP验证头

csharp
public static Memory<byte> UdpTop { get; }

Property Value

Memory<byte>

Methods

Dispose()

回收相关资源

csharp
public void Dispose()

GetFree(IPEndPoint, bool)

用于获取私有P2PServer服务器的通信消息

csharp
public static ValueTask<P2pServerAsync> GetFree(IPEndPoint endPoint, bool isTcp)

Parameters

endPoint IPEndPoint

服务器IP端口

isTcp bool

获取的P2P类型

Returns

ValueTask<P2pServerAsync>

成功后的结果

GetFreeTcp()

获取公共的P2PServer服务器的通信消息 TCP版本

csharp
public static ValueTask<P2pServerAsync> GetFreeTcp()

Returns

ValueTask<P2pServerAsync>

成功后的结果

GetFreeUdp()

获取公共的P2PServer服务器的通信消息 UDP版本

csharp
public static ValueTask<P2pServerAsync> GetFreeUdp()

Returns

ValueTask<P2pServerAsync>

成功后的结果

IsP2pAuth(Span<byte>, out Ipv4Port)

验证一个数据流,确定它是否是符合协议的P2P(发起)协议

csharp
public static bool IsP2pAuth(Span<byte> span, out Ipv4Port localEP)

Parameters

span Span<byte>

localEP Ipv4Port

Returns

bool

IsP2pWait(Span<byte>, out Ipv4Port)

验证一个数据流,确定它是否是符合协议的P2P(等待)协议

csharp
public static bool IsP2pWait(Span<byte> span, out Ipv4Port localEP)

Parameters

span Span<byte>

localEP Ipv4Port

Returns

bool

IsSuccess()

判断是否P2P是否可用

csharp
public bool IsSuccess()

Returns

bool

OkWait(CancellationToken)

判断是否通过双方等待验证

csharp
public bool OkWait(CancellationToken token)

Parameters

token CancellationToken

Returns

bool

P2PConnectAsync(TcpClientAsync, Ipv4Port, int)

尝试发起P2P连接,通过服务器验证确保可以更可靠的完成连接

csharp
public Task P2PConnectAsync(TcpClientAsync clientAsync, Ipv4Port RemoteEP, int timedDelay = 5000)

Parameters

clientAsync TcpClientAsync

要建立连接的对象

RemoteEP Ipv4Port

连接的对方设备

timedDelay int

尝试等待超时时间(不能小于1000ms)

Returns

Task

结果

Exceptions

Exception

不可用 或 模式不一致 或 超时!

P2PConnectAsync(UdpClientAsync, Ipv4Port, int)

尝试发起P2P连接,通过服务器验证确保可以更可靠的完成连接

csharp
public Task P2PConnectAsync(UdpClientAsync clientAsync, Ipv4Port RemoteEP, int timedDelay = 5000)

Parameters

clientAsync UdpClientAsync

要建立连接的对象

RemoteEP Ipv4Port

连接的对方设备

timedDelay int

尝试等待超时时间(不能小于1000ms)

Returns

Task

结果

Exceptions

Exception

不可用 或 模式不一致 或 超时!

基于Apache-2.0协议开源