private void startClient_video_path(string video_path)
        {
            byte[] bytes = new byte[9048];

            try
            {
                /*IPaddress dbCon = new DbConnection();
                 * string connetionString = dbCon.getConnection();*/
                IPaddress ip         = new IPaddress();
                string    connect_ip = ip.getIpaddress();
                IPAddress ipAddress  = new IPAddress(Encoding.ASCII.GetBytes(connect_ip));

                // Establish the remote endpoint for the socket.
                // This example uses port 11000 on the local computer.
                IPHostEntry ipHostInfo = Dns.GetHostEntry(Dns.GetHostName());
                //List<string> listIpAddress = new List()<string>;
                //listIpAddress.Add("192.168.0.104");
                // IPAddress ipAddress = new IPAddress(Encoding.ASCII.GetBytes("192.168.0.104")); //ipHostInfo.AddressList[1];
                IPEndPoint remoteEP = new IPEndPoint(ipAddress, 5005);

                // Create a TCP/IP  socket.
                socket = new Socket(ipAddress.AddressFamily,
                                    SocketType.Stream, ProtocolType.Tcp);

                // Connect the socket to the remote endpoint. Catch any errors.
                try
                {
                    socket.Connect(remoteEP);

                    string cam_url = "0";
                    //cam_url = video_path;
                    //cam_url = "rtspsrc location=rtsp://admin:[email protected]:4444 latency=2000 ! rtph264depay ! h264parse ! decodebin ! videoconvert ! appsink";
                    Console.WriteLine("Socket connected to {0}",
                                      socket.RemoteEndPoint.ToString());

                    // Encode the data string into a byte array.
                    byte[] msg = Encoding.ASCII.GetBytes(cam_url);

                    // Send the data through the socket.
                    int    bytesSent = socket.Send(msg);
                    string dataStr   = "";
                    // Receive the response from the remote device.
                    while (true)
                    {
                        int bytesRec = socket.Receive(bytes);
                        Console.WriteLine("Echoed test = {0}", bytesRec);
                        dataStr += Encoding.ASCII.GetString(bytes, 0, bytesRec);
                        //Console.WriteLine(dataStr);

                        /*if (bytes[bytesRec - 4] == 'E' & bytes[bytesRec - 3] == 'N' & bytes[bytesRec - 2] == 'D' & bytes[bytesRec - 1] == '!')
                         * {
                         *  Console.WriteLine("Echoed test = {0}", Encoding.ASCII.GetString(bytes, 0, bytesRec));
                         *  Console.WriteLine("end found " + bytesRec);
                         *  break;
                         * }*/
                        if (dataStr.Contains("END!"))
                        {
                            int index2 = dataStr.IndexOf("END!");
                            //Console.WriteLine("End found at::::" + index2);
                            int totLen = dataStr.Length;
                            //Console.WriteLine("length::::" + dataStr.Length);
                            //string mainData = dataStr.Substring(0, index2);
                            //if (index2 == mainData.Length)
                            //{
                            //    dataStr = dataStr.Substring(0, index2);
                            //}
                            //else
                            //{
                            string mainData = dataStr.Substring(0, index2);
                            //Console.WriteLine("main data length::::" + mainData.Length);
                            Image image = byteArrayToImage(mainData);
                            //pictureBox1.Image = image;
                            //if (pictureBox1.Image != null) { pictureBox1.Image.Dispose(); }
                            //pictureBox1.Image = (Image)image.Clone();
                            //pictureBox1.Update();
                            SetPicture(image);
                            //image.Dispose();
                            if (dataStr.Length == index2 + 4)
                            {
                                dataStr = "";
                            }
                            else if (dataStr.Length > (index2 + 4))
                            {
                                //Console.WriteLine("TEST TEST");
                                //Console.WriteLine("TEST TEST" + (index2 + 4));
                                string dataStr1 = dataStr.Substring(index2 + 4, (totLen - (index2 + 4)));
                                dataStr = dataStr1;
                            }
                            else
                            {
                            }
                            //}
                            //Console.WriteLine("remaining string::" + dataStr);
                        }
                    }

                    // Release the socket.
                    socket.Shutdown(SocketShutdown.Both);
                    socket.Close();
                }
                catch (ArgumentNullException ane)
                {
                    Console.WriteLine("ArgumentNullException : {0}", ane.ToString());
                }
                catch (SocketException se)
                {
                    Console.WriteLine("SocketException : {0}", se.ToString());
                }
                catch (Exception e)
                {
                    Console.WriteLine("Unexpected exception : {0}", e.ToString());
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }
        public void StartClient(string ip, string user, string pwd, string port, string use_case_id)
        {
            // Data buffer for incoming data.
            byte[] bytes = new byte[9048];

            try
            {
                IPaddress ip_A       = new IPaddress();
                string    connect_ip = ip_A.getIpaddress();
                // MessageBox.Show(connect_ip);
                IPHostEntry ipHostInfo = Dns.GetHostEntry(Dns.GetHostName());
                IPAddress   ipaddr     = IPAddress.Parse(connect_ip);
                //IPAddress ipAddress = new IPAddress(Encoding.ASCII.GetBytes(connect_ip));
                //MessageBox.Show(ipAddress.GetType().ToString());
                //Console.WriteLine("test"+ipaddr.GetType());

                // Establish the remote endpoint for the socket.
                // This example uses port 11000 on the local computer.

                //IPAddress ipAddress = IPAddress.Parse("192.168.0.104") ;// ipHostInfo.AddressList[1];
                IPEndPoint remoteEP = new IPEndPoint(ipaddr, 5005);

                // Create a TCP/IP  socket.
                socket = new Socket(ipaddr.AddressFamily,
                                    SocketType.Stream, ProtocolType.Tcp);

                // Connect the socket to the remote endpoint. Catch any errors.
                try
                {
                    socket.Connect(remoteEP);
                    string cam_url = "0";
                    if (ip == "0")
                    {
                        cam_url = ip + "~" + use_case_id + "~0";
                    }
                    else
                    {
                        cam_url = "rtsp://" + user + ":" + pwd + "@" + ip + ":" + port + "/H264?ch=1&subtype=0~" + use_case_id + "~0";
                    }
                    // cam_url = "http://"+ ip + ":" + port + "/videofeed?user=&password=~" + use_case_id + "~0";
                    //cam_url = "rtsp://"+user+":"+pwd+"@"+ip+":"+port+"/H264?ch=1&subtype=0";
                    //cam_url = "rtspsrc location=rtsp://admin:[email protected]:4444 latency=2000 ! rtph264depay ! h264parse ! decodebin ! videoconvert ! appsink";
                    Console.WriteLine("Socket connected to {0}",
                                      socket.RemoteEndPoint.ToString());
                    //cam_url = ip + "~" + use_case_id;

                    // Encode the data string into a byte array.
                    byte[] msg = Encoding.ASCII.GetBytes(cam_url);

                    // Send the data through the socket.
                    int    bytesSent = socket.Send(msg);
                    string dataStr   = "";
                    // Receive the response from the remote device.
                    while (true)
                    {
                        int bytesRec = socket.Receive(bytes);
                        //Console.WriteLine("Echoed test = {0}",bytesRec);
                        dataStr += Encoding.ASCII.GetString(bytes, 0, bytesRec);
                        //Console.WriteLine(dataStr);

                        /*if (bytes[bytesRec - 4] == 'E' & bytes[bytesRec - 3] == 'N' & bytes[bytesRec - 2] == 'D' & bytes[bytesRec - 1] == '!')
                         * {
                         *  Console.WriteLine("Echoed test = {0}", Encoding.ASCII.GetString(bytes, 0, bytesRec));
                         *  Console.WriteLine("end found " + bytesRec);
                         *  break;
                         * }*/
                        if (dataStr.Contains("END!"))
                        {
                            int index2 = dataStr.IndexOf("END!");
                            //Console.WriteLine("End found at::::" + index2);
                            int totLen = dataStr.Length;
                            //Console.WriteLine("length::::" + dataStr.Length);
                            //string mainData = dataStr.Substring(0, index2);
                            //if (index2 == mainData.Length)
                            //{
                            //    dataStr = dataStr.Substring(0, index2);
                            //}
                            //else
                            //{
                            string mainData = dataStr.Substring(0, index2);
                            //Console.WriteLine("main data length::::" + mainData.Length);
                            Image image = byteArrayToImage(mainData);
                            SetPicture(image);
                            //pictureBox1.Image = image;
                            //if (pictureBox1.Image != null) { pictureBox1.Image.Dispose(); }
                            //pictureBox1.Image = (Image)image.Clone();
                            //pictureBox1.Update();
                            //image.Dispose();
                            if (dataStr.Length == index2 + 4)
                            {
                                dataStr = "";
                            }
                            else if (dataStr.Length > (index2 + 4))
                            {
                                //Console.WriteLine("TEST TEST");
                                //Console.WriteLine("TEST TEST" + (index2 + 4));
                                string dataStr1 = dataStr.Substring(index2 + 4, (totLen - (index2 + 4)));
                                dataStr = dataStr1;
                            }
                            else
                            {
                            }
                            //}
                            //Console.WriteLine("remaining string::" + dataStr);
                        }
                    }

                    // Release the socket.
                    socket.Shutdown(SocketShutdown.Both);
                    socket.Close();
                }
                catch (ArgumentNullException ane)
                {
                    MessageBox.Show("No Ip Found");
                    Console.WriteLine("ArgumentNullException : {0}", ane.ToString());
                }
                catch (SocketException se)
                {
                    MessageBox.Show("No Socket Found");
                    Console.WriteLine("SocketException : {0}", se.ToString());
                }
                catch (Exception e)
                {
                    MessageBox.Show("No test Found");
                    Console.WriteLine("Unexpected exception : {0}", e.ToString());
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }
        private void StartClient(string ip, string user, string pwd, string port, string cams_id)
        {
            byte[] bytes = new byte[9048];

            try
            {
                IPaddress   ip_A       = new IPaddress();
                string      connect_ip = ip_A.getIpaddress();
                IPHostEntry ipHostInfo = Dns.GetHostEntry(Dns.GetHostName());
                IPAddress   ipaddr     = IPAddress.Parse(connect_ip);
                IPEndPoint  remoteEP   = new IPEndPoint(ipaddr, 5006);
                socket = new Socket(ipaddr.AddressFamily,
                                    SocketType.Stream, ProtocolType.Tcp);
                try
                {
                    socket.Connect(remoteEP);
                    string cam_url = "0";
                    if (ip == "0")
                    {
                        cam_url = ip + "~" + cams_id + "~0";
                    }
                    else
                    {
                        cam_url = "rtsp://" + user + ":" + pwd + "@" + ip + ":" + port + "/H264?ch=1&subtype=0~" + cams_id + "~0";
                    }
                    // cam_url = "http://"+ ip + ":" + port + "/videofeed?user=&password=~" + cam_id + "~0";
                    //cam_url = "rtsp://"+user+":"+pwd+"@"+ip+":"+port+"/H264?ch=1&subtype=0";
                    //cam_url = "rtspsrc location=rtsp://admin:[email protected]:4444 latency=2000 ! rtph264depay ! h264parse ! decodebin ! videoconvert ! appsink";
                    Console.WriteLine("Socket connected to {0}",
                                      socket.RemoteEndPoint.ToString());
                    byte[] msg       = Encoding.ASCII.GetBytes(cam_url);
                    int    bytesSent = socket.Send(msg);
                    string dataStr   = "";
                    while (true)
                    {
                        int bytesRec = socket.Receive(bytes);
                        dataStr += Encoding.ASCII.GetString(bytes, 0, bytesRec);
                        if (dataStr.Contains("END!"))
                        {
                            int    index2   = dataStr.IndexOf("END!");
                            int    totLen   = dataStr.Length;
                            string mainData = dataStr.Substring(0, index2);
                            Image  image    = byteArrayToImage(mainData);
                            SetPicture(image);
                            if (dataStr.Length == index2 + 4)
                            {
                                dataStr = "";
                            }
                            else if (dataStr.Length > (index2 + 4))
                            {
                                string dataStr1 = dataStr.Substring(index2 + 4, (totLen - (index2 + 4)));
                                dataStr = dataStr1;
                            }
                            else
                            {
                            }
                        }
                    }
                    socket.Shutdown(SocketShutdown.Both);
                    socket.Close();
                }
                catch (ArgumentNullException ane)
                {
                    MessageBox.Show("No Ip Found");
                    Console.WriteLine("ArgumentNullException : {0}", ane.ToString());
                }
                catch (SocketException se)
                {
                    MessageBox.Show("No Socket Found");
                    Console.WriteLine("SocketException : {0}", se.ToString());
                }
                catch (Exception e)
                {
                    Console.WriteLine("Unexpected exception : {0}", e.ToString());
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }