1.
That is because all socket code is running on a separate thread, in order to access the controls you need to use Invoke. Heres an example that will fix the problem you posted:
Now instead of doing:VB.Net Code:
Private Delegate Sub StringDelegate(text As String) Private Sub SetConnectionLabelText(text As String) If Me.LblConnection.InvokeRequired Then Me.Invoke(New StringDelegate(AddressOf SetConnectionLabelText), text) Else Me.LblConnection.Text = text End If End Sub
Do:VB.Net Code:
LblConnection.Text = "Connected"
VB.Net Code:
SetConnectionLabelText("Connected")
2.
If you want to send messages from the server, simply iterate through the list of connected clients and call the SendMessage method on the client you want to send a message to.
EDIT: Oh, I see that I've made a silly misstake in my code. Try it now.




Reply With Quote