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.
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.