Beispiel #1
0
        void mi_Click(object sender, EventArgs e)
        {
            Cell c = this.squareListView1.SelectedCell;

            if (c == null)
            {
                return;
            }

            ToolStripMenuItem menuItem = sender as ToolStripMenuItem;

            HostConfiguration host = menuItem.Tag as HostConfiguration;

            TcpClient tcp = new TcpClient();

            System.Net.IPAddress  ip = System.Net.IPAddress.Parse(host.ip);
            System.Net.IPEndPoint ep = new System.Net.IPEndPoint(ip, 20000);
            try
            {
                ConnectInfo info = new ConnectInfo()
                {
                    Socket = tcp, Target = c, Source = host
                };

                LiveClient lc = new LiveClient(tcp);
                lc.Tag = info;

                tcp.BeginConnect(ip, 20000, this.ConnectCallback, lc);
            }
            catch (System.Net.Sockets.SocketException)
            {
                MessageBox.Show(this, "无法连接, 请检查设备", "连接错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
Beispiel #2
0
        private void ConnectCallback(IAsyncResult ar)
        {
            LiveClient  lc   = ar.AsyncState as LiveClient;
            ConnectInfo info = lc.Tag as ConnectInfo;

            try
            {
                info.Socket.EndConnect(ar);
            }
            catch (System.Net.Sockets.SocketException)
            {
                string msg = string.Format("无法连接 {0}, 请检查设备", info.Source.Config.Name);

                Action showMsg = () => MessageBox.Show(this, msg, "连接错误", MessageBoxButtons.OK, MessageBoxIcon.Error);

                this.BeginInvoke(showMsg);

                return;
            }

            if (CellCameraMap.ContainsKey(info.Target))
            {
                CellCameraMap[info.Target].ImageReceived -= this.lc_ImageReceived;

                CellCameraMap[info.Target].Stop();

                CellCameraMap.Remove(info.Target);
            }


            lc.ImageReceived  += new EventHandler <ImageCapturedEventArgs>(lc_ImageReceived);
            lc.ConnectAborted += new EventHandler(lc_ConnectAborted);
            lc.Start();

            CellCameraMap.Add(info.Target, lc);
        }
Beispiel #3
0
        void mi_Click(object sender, EventArgs e)
        {
            Cell c = this.squareListView1.SelectedCell;

            if (c == null) return;

            ToolStripMenuItem menuItem = sender as ToolStripMenuItem;

            Camera cam = menuItem.Tag as Camera;

            TcpClient tcp = new TcpClient();
            System.Net.IPAddress ip = System.Net.IPAddress.Parse(cam.IpAddress);
            System.Net.IPEndPoint ep = new System.Net.IPEndPoint(ip, 20000);
            try
            {
                ConnectInfo info = new ConnectInfo() { Socket = tcp, Target = c, Source = cam };

                LiveClient lc = new LiveClient(tcp);
                lc.Tag = info;

                tcp.BeginConnect(ip, 20000, this.ConnectCallback, lc);

            }
            catch (System.Net.Sockets.SocketException)
            {
                MessageBox.Show(this, "无法连接, 请检查设备", "连接错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
Beispiel #4
0
        void lc_ConnectAborted(object sender, EventArgs e)
        {
            LiveClient lc = sender as LiveClient;

            this.CellCameraMap.Remove((lc.Tag as ConnectInfo).Target);
        }