private async Task doExecute(QpCommandHandler handler, ConnectCommand cmd) { var commandContent = cmd.ContentT; var tcpClient = new TcpClient(); Portal portal = null; try { await tcpClient.ConnectAsync(commandContent.Host, commandContent.Port); portal = new Portal(handler, tcpClient, commandContent.SendInterval); portal.Stoped += (sender, e) => { tcpClient.Close(); var channel = handler as QpServerChannel; channel?.Stop(); }; portal.Start(); lock (portalList) portalList.Add(portal); await handler.SendCommandResponse(cmd, 0, null); } catch (Exception ex) { if (portal != null) { lock (portalList) if (portalList.Contains(portal)) { portalList.Remove(portal); } } await handler.SendCommandResponse(cmd, -1, ex.Message); } }
public Portal(QpCommandHandler handler, TcpClient tcpClient, int packageSendInterval, int bufferSize) { this.handler = handler; this.tcpClient = tcpClient; this.packageSendInterval = packageSendInterval; this.stream = tcpClient.GetStream(); send_buffer = new byte[bufferSize]; }
public override void Execute(QpCommandHandler handler, ConnectCommand cmd) { _ = doExecute(handler, cmd); }
public Portal(QpCommandHandler handler, TcpClient tcpClient, int packageSendInterval) : this(handler, tcpClient, packageSendInterval, 80 * 1024) { }
public override void Execute(QpCommandHandler handler, GetVersionCommand cmd) { handler.SendCommandResponse(cmd, 0, this.GetType().Assembly.GetName().Version); }