public override void Start()
        {
            //清空上次的显示内容
            Image1 = null;
            Image2 = null;
            Image3 = null;
            Image4 = null;

            if (!string.IsNullOrEmpty(Url2))
            {
                videoPlayHelper1 = new VideoPlayHelper(Url2, (x) => { Image2 = x; });
            }

            remote_ip = ConfigurationManager.AppSettings["TcpServerIp"];
            tcpClient = new TcpClient(remote_ip, remote_port);
            Console.WriteLine($"tcp connect: ({remote_ip}, {remote_port})");

            stream = tcpClient.GetStream();

            //发送角色数据包
            Role role = new Role(3, 1, 1);

            byte[] send_bytes = StructToBytesHelper.StructToBytes <Role>(role);
            stream.WriteAsync(send_bytes, 0, send_bytes.Length);
            Console.WriteLine("send_role_packet");

            //发送获取图像请求命令包
            VideoCmd videoCmd = new VideoCmd(1, 5, RoomId, 1);

            byte[] videoCmd_bytes = StructToBytesHelper.StructToBytes <VideoCmd>(videoCmd);
            stream.WriteAsync(videoCmd_bytes, 0, videoCmd_bytes.Length);
            Console.WriteLine("send_get_video_packet");

            //接收图像数据并显示
            cancellationTokenSource = new CancellationTokenSource();
            Task recvVideoTask = new Task(async() =>
            {
                try
                {
                    await RecvVideo(cancellationTokenSource.Token);
                }
                catch (OperationCanceledException)
                {
                }
                stream?.Close();
                tcpClient?.Close();
            }, cancellationTokenSource.Token);

            recvVideoTask.Start();
            videoPlayHelper1?.Start();
        }
예제 #2
0
        public override void Stop()
        {
            //发送关闭图像命令
            //VideoCmd videoCmd = new VideoCmd(1, 5, RoomId, 0);
            //byte[] videoCmd_bytes = StructToBytesHelper.StructToBytes<VideoCmd>(videoCmd);
            //stream.Write(videoCmd_bytes, 0, videoCmd_bytes.Length);
            //发送关闭连接命令
            Role exit_role = new Role(4, 1, 1);

            byte[] exit_bytes = StructToBytesHelper.StructToBytes <Role>(exit_role);
            stream.Write(exit_bytes, 0, exit_bytes.Length);

            cancellationTokenSource.Cancel();
        }