void HeartAsync() { TaskHelper.Start(() => { try { while (true) { if (_client.Connected) { if (Actived.AddMilliseconds(HeartSpan) <= DateTimeHelper.Now) { var sm = new BaseSocketProtocal() { BodyLength = 0, Type = (byte)SocketProtocalType.Heart }; _client.SendAsync(sm.ToBytes()); } ThreadHelper.Sleep(HeartSpan); } else { ThreadHelper.Sleep(1000); } } } catch { } }); }
/// <summary> /// 基础发送数据 /// </summary> /// <param name="protocalType"></param> /// <param name="data"></param> void BaseSend(ProtocalType protocalType, byte[] data) { var p = new BaseSocketProtocal(); p.Type = (byte)protocalType; p.Content = data; if (p.Content != null) { p.BodyLength = p.Content.Length; } else { p.BodyLength = 0; } _udpClient.SendAsync(p.ToBytes()); }
void BaseReply(string id, ProtocalType protocalType, byte[] data) { var p = new BaseSocketProtocal(); p.Type = (byte)protocalType; p.Content = data; if (p.Content != null) { p.BodyLength = p.Content.Length; } else { p.BodyLength = 0; } _udpServer.SendAsync(id, p.ToBytes()); }
/// <summary> /// SendAsync /// </summary> /// <param name="id"></param> /// <param name="baseSocketProtocal"></param> protected void SendAsync(string id, BaseSocketProtocal baseSocketProtocal) { _udpServer.SendAsync(id, baseSocketProtocal.ToBytes()); }
public void SendAsync(BaseSocketProtocal protocal) { _udpClient.SendAsync(protocal.ToBytes()); }