Ejemplo n.º 1
0
        public void interface_thread(string interface_ipaddress)
        {
            try
            {
                TcpListener listener1;
                listener1 = new TcpListener(IPAddress.Parse(interface_ipaddress), 2055);
                listener_list.Add(listener1);
                while (true)
                {

                    try
                    {
                        listener1.Start();
                        // MessageBox.Show("hell");
                        Socket soc1 = listener1.AcceptSocket();
                        socket_list.Add(soc1);
                        //MessageBox.Show("hell1");

                        string c_ip1 = (((IPEndPoint)soc1.RemoteEndPoint).Address.ToString());

                        string name = "";

                        if (!live_list.ContainsKey(c_ip1))
                        {

                            try
                            {
                                IPHostEntry hostEntry = Dns.GetHostEntry(c_ip1);
                                name = hostEntry.HostName;
                            }
                            catch (SocketException ex)
                            {
                                name = "?";
                            }
                            my_data_struct node = new my_data_struct();
                            node.connection_type = "server";
                            node.sock = soc1;
                            node.client = null;
                            node.resolve_name = name;
                            live_list.Add(c_ip1, node);

                            ListViewItem current_ip = new ListViewItem(name);
                            current_ip.SubItems.Add(c_ip1);
                            listView1.Items.Add(current_ip);
                            Thread service_thread1 = new Thread(() => Service(soc1, name, c_ip1));
                            myThreads.Add(service_thread1);
                            service_thread1.IsBackground = true;
                            service_thread1.Start();

                        }
                    }
                    catch (Exception e)
                    { }

                    Thread.Sleep(10);

                }
            }
            catch (Exception q)
            {
                // MessageBox.Show(q.GetType().ToString());
                // MessageBox.Show("k" + q.Message);
            }
        }
Ejemplo n.º 2
0
        public void connect(string ipadress, ListView listView1, Hashtable live_list)
        {
            try
            {
                TcpClient tcp_check = new TcpClient();
                try
                {
                    tcp_check.Connect(ipadress, 2055);
                }
                catch (Exception e)
                {
                    return;
                }
                string name = null;
                try
                {
                    IPHostEntry hostEntry = Dns.GetHostEntry(ipadress);
                    name = hostEntry.HostName;
                }
                catch (SocketException ex)
                {
                    name = "?";
                }

                //string name = "?";
                my_data_struct node = new my_data_struct();
                node.connection_type = "client";
                node.client = tcp_check;
                node.sock = null;
                node.resolve_name = name;
                live_list.Add(ipadress, node);
                ListViewItem item = new ListViewItem(name);
                item.SubItems.Add(ipadress);
                listView1.Items.Add(item);
                Thread service_thread = new Thread(() => Service(tcp_check, name, ipadress));
                myThreads.Add(service_thread);
                service_thread.IsBackground = true;

                service_thread.Start();

            }
            //  listView1.SelectedItems[i].SubItems[0] = name;
            //listView1.SelectedItems[i].SubItems[1] = pieces[0];
            catch (Exception e)
            { //MessageBox.Show("connect" + e.Message);
            }
        }