Results 1 to 40 of 163

Thread: [RESOLVED] [2008] Can I add a TCPClient Component

Threaded View

  1. #11
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [2008] Can I add a TCPClient Component

    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:
    VB.Net Code:
    1. Private Delegate Sub StringDelegate(text As String)
    2.  
    3. Private Sub SetConnectionLabelText(text As String)
    4. If Me.LblConnection.InvokeRequired Then
    5.     Me.Invoke(New StringDelegate(AddressOf SetConnectionLabelText), text)
    6. Else
    7.     Me.LblConnection.Text = text
    8. End If
    9. End Sub
    Now instead of doing:
    VB.Net Code:
    1. LblConnection.Text = "Connected"
    Do:
    VB.Net Code:
    1. 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.
    Last edited by Atheist; Jan 2nd, 2008 at 03:29 PM.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width