Results 1 to 18 of 18

Thread: [RESOLVED] TCP/IP - Host can't display received messages :(

  1. #1

    Thread Starter
    Hyperactive Member knxrb's Avatar
    Join Date
    Jul 2007
    Location
    United Kingdom
    Posts
    321

    Resolved [RESOLVED] TCP/IP - Host can't display received messages :(

    Hi guys, I can't get the host/server to display messages from the client.
    It receives the messages but when I try and get it to put it into a listbox it says it's added it but is doesn't add anything.

    Full project source attached.

    Please help me ASAP as this is very important

    Thanks in advance, knxrb
    Attached Files Attached Files
    Did I help you with your problem? If I did rate me by clicking here: Rate knxrb

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

    Re: TCP/IP - Host can't display received messages :(

    I dont suppose you could just post the code snippets that does the actual sending/receiving?
    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)

  3. #3

    Thread Starter
    Hyperactive Member knxrb's Avatar
    Join Date
    Jul 2007
    Location
    United Kingdom
    Posts
    321

    Re: TCP/IP - Host can't display received messages :(

    Here's the code for when the host receives the message, when I put a messagebox before or after adding it to the listbox it shows the correct message in the messagebox, it just won't show it in the listbox

    Code:
        Public Sub Message(ByVal sender As ConnectedClient, ByVal message As String)
            Dim data() As String = message.Split("|")
            If data(0) = "CONNECT" Then
                sender.Username = data(1)
            ElseIf data(0) = "DISCONNECT" Then
                Host.removeClient(sender)
            Else
                ''data(0) = username & data(1) = message
                Dim strMessage As String = data(0) & ": " & data(0)
                Host.lstJMessages.Items.Add(strMessage)
            End If
        End Sub
    Did I help you with your problem? If I did rate me by clicking here: Rate knxrb

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

    Re: TCP/IP - Host can't display received messages :(

    From where are you calling the Message subroutine? Are you executing the method on the same thread that the ListBox was created on?
    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)

  5. #5

    Thread Starter
    Hyperactive Member knxrb's Avatar
    Join Date
    Jul 2007
    Location
    United Kingdom
    Posts
    321

    Re: TCP/IP - Host can't display received messages :(

    Are you executing the method on the same thread that the ListBox was created on?
    Aah! Each client is on a seperate thread so it won't be calling it on the listbox thread!

    Do you know how do I solve this?

    knxrb
    Did I help you with your problem? If I did rate me by clicking here: Rate knxrb

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

    Re: TCP/IP - Host can't display received messages :(

    Quote Originally Posted by knxrb View Post
    Aah! Each client is on a seperate thread so it won't be calling it on the listbox thread!

    Do you know how do I solve this?

    knxrb
    That would be the cause then
    You'd need to do some safe cross-thread calls. jmcilhinney has a good article on this here.
    Dont be put off by the size of the article though, its a pretty simple thing.
    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)

  7. #7

    Thread Starter
    Hyperactive Member knxrb's Avatar
    Join Date
    Jul 2007
    Location
    United Kingdom
    Posts
    321

    Re: TCP/IP - Host can't display received messages :(

    I've added the code and changed it to add the item into the listbox but it doesn't work.
    Am I putting the code in the message received module and calling it there or in my host form and calling it from the module?

    Code:
        Private Delegate Sub AddItemInvoker(ByVal text As String)
    
        Private Sub AddItem(ByVal text As String)
            If Host.lstMessages.InvokeRequired Then
                Host.lstMessages.Invoke(New AddItemInvoker(AddressOf AddItem), New Object() {text})
            Else
                Host.lstMessages.Items.Add(text)
            End If
        End Sub
    Did I help you with your problem? If I did rate me by clicking here: Rate knxrb

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

    Re: TCP/IP - Host can't display received messages :(

    I dont know what 'module' you're talking about but you'd be best off putting it in your form.
    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)

  9. #9

    Thread Starter
    Hyperactive Member knxrb's Avatar
    Join Date
    Jul 2007
    Location
    United Kingdom
    Posts
    321

    Re: TCP/IP - Host can't display received messages :(

    So how do I call it from a module because it's a private sub and when I make it public it doesn't change anything, it still doesn't add the item to the listbox?

    knxrb
    Did I help you with your problem? If I did rate me by clicking here: Rate knxrb

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

    Re: TCP/IP - Host can't display received messages :(

    How does your module look? Could it be that you're calling the method on the wrong instance of the form?
    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)

  11. #11

    Thread Starter
    Hyperactive Member knxrb's Avatar
    Join Date
    Jul 2007
    Location
    United Kingdom
    Posts
    321

    Re: TCP/IP - Host can't display received messages :(

    The module and the rest of the project files are in the attachment from the first post.

    Could it be that you're calling the method on the wrong instance of the form?
    I'm not sure

    knxrb
    Did I help you with your problem? If I did rate me by clicking here: Rate knxrb

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

    Re: TCP/IP - Host can't display received messages :(

    I'm not sure why you're calling MR.Message(Me, message) in the ConnectedClient class, as it already provides a DataReceived event that you can use, which will only be raised when a full message has been received. Just add an eventhandler for the DataReceived event after you've created the ConnectedClient in your form. That will mean that you basically will have to move your "Message" subroutine into your form code, which will also mean that you will be able to call the AddItem method correctly.
    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)

  13. #13

    Thread Starter
    Hyperactive Member knxrb's Avatar
    Join Date
    Jul 2007
    Location
    United Kingdom
    Posts
    321

    Re: TCP/IP - Host can't display received messages :(

    Oh right, I'll try that now, thanks

    knxrb
    Did I help you with your problem? If I did rate me by clicking here: Rate knxrb

  14. #14

    Thread Starter
    Hyperactive Member knxrb's Avatar
    Join Date
    Jul 2007
    Location
    United Kingdom
    Posts
    321

    Re: TCP/IP - Host can't display received messages :(

    I can't get it to work

    I've attached the project as it is now and I've got it calling the event in the form etc..

    knxrb
    Attached Files Attached Files
    Did I help you with your problem? If I did rate me by clicking here: Rate knxrb

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

    Re: TCP/IP - Host can't display received messages :(

    The way the ConnectedClient class works is that it classifies a "complete" message as a string ending with ControlChars.Cr. Are you taking that into mind when you send data? Each message must end with ControlChars.Cr.

    I know thats a "bad" way of doing it, I'm going to upload a new ConnectedClient class to my example here on VBForums shortly (I've been saying 'shortly' for quite a while now though...)
    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)

  16. #16

    Thread Starter
    Hyperactive Member knxrb's Avatar
    Join Date
    Jul 2007
    Location
    United Kingdom
    Posts
    321

    Re: TCP/IP - Host can't display received messages :(

    I didn't know it needed to end with that.
    Is that why it doesn't display it?

    [Edit] Adding ControlChars.Cr to the end of the messages doesn't make it display

    knxrb
    Did I help you with your problem? If I did rate me by clicking here: Rate knxrb

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

    Re: TCP/IP - Host can't display received messages :(

    Are you even receiving the messages as the code is right now? Can you step through the code and verify that the dataReceived event is indeed being raised?
    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)

  18. #18

    Thread Starter
    Hyperactive Member knxrb's Avatar
    Join Date
    Jul 2007
    Location
    United Kingdom
    Posts
    321

    Re: TCP/IP - Host can't display received messages :(

    It's working! I've previously removed a line of code from ConnectedClient.vb class and forgot to put it back

    Thanks for your time and help

    knxrb
    Did I help you with your problem? If I did rate me by clicking here: Rate knxrb

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