List of computers currently connected in the dropdown list

I want to display all currently connected computers in a dropdown, so the user can choose which computer on the network is sending the message using the combobox, but not sure how to implement it.

public partial class WCF : Form
{
    public WCF()
    {
        InitializeComponent();
    }

    private void WCF_Load(object sender, EventArgs e)
    {
        ServiceHost svc = new ServiceHost(typeof(ApplicationService));
        svc.Credentials.Peer.MeshPassword = "hehe";
        svc.Open();
    }
}


[ServiceContract]
public interface IApplicationService
{
    [OperationContract(IsOneWay = true)]
    void lol();
}

public class ApplicationService : IApplicationService
{
    public void lol()
    {
        Console.WriteLine("lol");
    }

}

      

}

So far, I have a Winform that can connect to each other over TCP. I just need a way to display the established connections for all current clients in combobox1. Thanks to

+3


source to share


1 answer


First create an Arraylist object and every time you accept a new client connection you must keep the socket for further processing.

        ArrayList arr = new ArrayList();
        while (true)
        {
            Main_Client = Main_Listener.AcceptTcpClient();
            arr.Add(Main_Client);                                
        }

      



This will add each client connection to the combo box

        foreach (object obj in arr) 
        {                
            comboBox1.Items.Add(obj);
        }

      

+2


source







All Articles