views:

21

answers:

1

Hello all!

I'm currently following the great tutorial on Geekpedia to create my own Chat Client and Chat Server.

Connecting the clients to the server works fine but I'm experiencing a few issues with the text being displayed in the chat log.

The first message that is displayed is in the Server window then the incoming connections are monitored:

Image 1

Then I go to connect the Client to the host, all is fine and the appropriate log messages are displayed:

Image 2

Now when I go to send a simple message the Line.Length property shows 3, in particular notice the text:

Image 3

Also, the .Text property contains everything, not just the current line:

alt text

Now looking at the Server and Client window you'll notice the text has some how copied itself in the wrong places and the previous message is overwritten:

Image 4

If I press the Send button again (With the same string/message) I notice this in the debugger:

Image 5

The text in the Server window does not move further down the box, it seems to overwrite what was previously there. Also the text in the Client window has gone:

Image 6

So if I press the send text button again we see this for the Line property:

Image 7

I'm at a complete loss, I spent a good few hours debugging the code and even after using a diff tool to compare the original code to mine it's all the same (With exception to certain words in different cases).

If I run the original source code and inspect the same Length property I notice that the count is 1 and the .Text property is only one line:

Image 8

Everything displays correctly:

Image 9

Does anybody have any idea what's going on? Now I know an option is to simply use the source code itself but I want to "learn by doing" and would like to know why this is happening and how to fix it.

Thanks for your time!

+1  A: 

I am just taking a shot in the dark here, but the SendMessage method in your modified code uses the text from the chatWindow control. The SendMessage in the original code uses the text from txtMessage. I think you are using the text from the wrong control.

kevev22
Well spotted! The text is correctly displayed on the Server log but now on the Client window each new message overwrites the previous one, essentially the Client only has a record of the previous statement. =[
Jamie Keeling
Just check to make sure that you are not clearing the text from chatWindow anywhere. In SendMessage in your post you are clearing the text twice - chatWindow.Lines = null and chatWindow.Text = ""
kevev22
Good spot! Cant't believe the mistakes were so obvious. Thanks for the fresh pair of eyes =]
Jamie Keeling