Console chat server. How to stop stream to client.
Hello all. I am building a chat client/server.
Everything on the client end now works fine, but I am having problems with my console based server. Users can connect and chat just fine, but when a user disconnects, the server does not know how recognize this, often spamming the last message that was sent by the user, follow by the server app crashing.
I need to find a way to stop streaming info to the user (and what ever else I need to stop to keep the server from crashing) and broadcast a message that says which user is disconnecting.
This is my first chat/client program so I'm kinda lost as what I should do... Any help!? Thanks!
Once the client disconnects and no longer sends data, the server crashes. I think I had it backwards earlier, I need to stop attempting to read data from a client. As I said this is my first server, most of the code is from a tutorial.
Last edited by BowserYo; Apr 2nd, 2009 at 01:23 PM.
Re: Console chat server. How to stop stream to client.
You'll have to replace those with the name of your socket variable, and the proper name for the disconnected state, which will pop up after the equals sign. (I don't have VB available at the moment.)
Re: Console chat server. How to stop stream to client.
Since it's telling that it can't do anything with something that's closed, put an Exit Do in the Catch block. This will exit your loop should the connection fail sometime between the loop start and the stream being created.
I'm used to asyncronous connections, so forgive me, since I dont' work with Syncronous.
Re: Console chat server. How to stop stream to client.
dbasnett: I was trying that a while before I knew about these forums. Thats how I found the code I am using it now, I am trying to modify it to suit my needs, and learn something at the same time.
Re: Console chat server. How to stop stream to client.
This program is not the MSDN program, I found those on another website. If we are thinking of the same chat program, the one I tried turned out to be a lot more complicated.
Re: Console chat server. How to stop stream to client.
In order to get to a more specific answer, I'm going to have to need access to a VB client, but that's not going to be for at least another 2 days (work schedule.) I'm not ignoring you.
Re: Console chat server. How to stop stream to client.
Okay. I found out your issue. Basically, what's happening is that the socket is trying to get data from a stream that it is no longer connected to. So, I solved that by putting an IF block into the loop that throws an event to clean up.
Also, I moved the Client object OUTSIDE of the module block. It's more confusing with it inside.
Please throw this into a new folder so that you can look at and compare the difference.