Well, since you dont have any good unique identifier like a username or something of the sort, you have 3 options:
1. Simply add each ConnectedClient instance in the collection to the Listbox, since the listbox can have any kind of object added to it. This wont be pretty as each item will look the same in the listbox..something like this: [ProjectName].UserConnection
The only advantage is that the listbox will return a ConnectedClient in the SelectedItem property that you can use easily:
VB.Net Code:
Ctype(ListBox1.SelectedItem, ConnectedClient).SendMessage("hello")
2. This is another option:
Each client will now be represented by their index in the listbox. To send a message to a client by index you do:VB.Net Code:
For i As Integer = 0 To clients.Count-1 ListBox1.Items.Add(i) Next i
VB.Net Code:
clients.item(Cint(ListBox1.SelectedItem)).SendMessage("hello")
3. The final option: This is the best option if you want to be able to identify a specific client from the rest.
Upon connection, have the client send a username that it wants to use. The server receives the username, checks so that it isnt already in use, then assigns it to the instance of ConnectedClient from which the message was received. This username can then be used to display every client in a list.




Reply With Quote