Пример #1
0
        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);
            }
        }
Пример #2
0
 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];
 }
Пример #3
0
 public override void Execute(QpCommandHandler handler, ConnectCommand cmd)
 {
     _ = doExecute(handler, cmd);
 }
Пример #4
0
 public Portal(QpCommandHandler handler, TcpClient tcpClient, int packageSendInterval) : this(handler, tcpClient, packageSendInterval, 80 * 1024)
 {
 }
Пример #5
0
 public override void Execute(QpCommandHandler handler, GetVersionCommand cmd)
 {
     handler.SendCommandResponse(cmd, 0, this.GetType().Assembly.GetName().Version);
 }