Problems Finding Bugs

ads103

New member
Joined
Jul 20, 2011
Messages
2
Programming Experience
Beginner
Hello, all. I'm a novice VB.NET programmer, and I'm writing a chat room application. It consists of a tcp client and server program. So far I can make multiple instances of the client connect to the server, and they will communicate, but I've got several bugs that I'm having a hard time finding the cause of, let alone killing.

The programs work simply by converting strings into byte arrays, and sending the array to all connected clients. Just recently, I added a feature that lets each connected client choose a color for their text. I add a two-character prefix to each message string, which identifies the color. For example, a message that reads "Hi" would say "reHi" to indicate the red color. Of course, when the message displays, I dont want the "re" to show, so I use Substring(2). This works when the first client connects. However, when the second client connects, the "re" is visible. And when the third client connects, the "re" appears twice. Fourth client, thrice, and so on. The code for every client is identical; I can find no reason for this to happen and would like help fixing it.

Additionally, having a client disconnect from the server is buggy at best. I accomplish disconnection simply by using "End" clientside, killing the client. When the server finds that the client disconnects, an exception gets thrown, and the client is removed from a hashtable I use to store the names of all clients. When this happens, the disconnected client's last message gets broadcasted a second, third, fourth, or more time, basically spamming the chat history.

These are just two of my annoying issues. I hope I was informative enough, and that someone will be able to lend this novice a helping hand with these and a few more odd things. Thanks in advance.
 
I fixed the first issue I have listed above.
To broadcast a message to each client, one at a time, the server uses a for-next loop. I had a line of code that took the two-character prefix for color off of the message, and attached it to the username, so that when the client got the username, it would start with the two character prefix. Because of where I had placed the conversion code, the program would add the two-character prefix for each client it broadcasted to. Simply by moving this code outside of the for-next loop, I fixed my first problem.

One bug down, a whole bunch more to go.
 

Latest posts

Back
Top