|
-
Apr 21st, 2009, 06:32 AM
#1
Thread Starter
Hyperactive Member
-
Apr 21st, 2009, 06:37 AM
#2
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?
-
Apr 21st, 2009, 06:40 AM
#3
Thread Starter
Hyperactive Member
-
Apr 21st, 2009, 06:43 AM
#4
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?
-
Apr 21st, 2009, 06:45 AM
#5
Thread Starter
Hyperactive Member
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

-
Apr 21st, 2009, 06:50 AM
#6
Re: TCP/IP - Host can't display received messages :(
 Originally Posted by knxrb
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.
-
Apr 21st, 2009, 07:06 AM
#7
Thread Starter
Hyperactive Member
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

-
Apr 21st, 2009, 07:09 AM
#8
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.
-
Apr 21st, 2009, 07:12 AM
#9
Thread Starter
Hyperactive Member
-
Apr 21st, 2009, 07:15 AM
#10
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?
-
Apr 21st, 2009, 07:17 AM
#11
Thread Starter
Hyperactive Member
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

-
Apr 21st, 2009, 07:29 AM
#12
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.
-
Apr 21st, 2009, 07:30 AM
#13
Thread Starter
Hyperactive Member
-
Apr 21st, 2009, 07:34 AM
#14
Thread Starter
Hyperactive Member
-
Apr 21st, 2009, 07:46 AM
#15
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...)
-
Apr 21st, 2009, 07:53 AM
#16
Thread Starter
Hyperactive Member
-
Apr 21st, 2009, 07:58 AM
#17
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?
-
Apr 21st, 2009, 08:05 AM
#18
Thread Starter
Hyperactive Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|