Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

java chat server

  Asked By: Lloyd    Date: Sep 28    Category: Java    Views: 1347
  

I can't get my chat server to disconnect clients that have closed
their chat window immediatly.

The code is in files/Jonathan/Server code
(I'm not putting it in this post because that would mean I'd have to
take out the indentation, maybe everyone else on this list should
learn from me)

Share: 

 

4 Answers Found

 
Answer #1    Answered By: May Hansen     Answered On: Sep 28

You didn't give me enough code  to tell if this is will fix it but
here it goes:

If you are extending Frame, then go to the method where you are
checking for the Window close, when it closes, just disconnect. If
you're extending JFrame, you'll have to overwrite their method.
Sorry I would elaborate but the bell rings in 2 minutes and then I
have US History.

 
Answer #2    Answered By: Abana Cohen     Answered On: Sep 28


Ok... That code  is the server... the client(of which there can be as
many as you like...thousands) is running a different program...
I wan't to find out if the client is still connected on the other end.
Thats what this part of the code is all about:

/*30*/ if(/*find out if client has disconnected*/)
/*31*/ {
/*32*/ removeConnection(i);
/*33*/ }

is there some kind of method in java.net.Socket that can figure out if
the client has disconnected?
I've tried quite a few methods, but none of them seem to work.

 
Answer #3    Answered By: Lu Fischer     Answered On: Sep 28

I don't know if this will help, but here is what I did last year in my
second year networking subject.

Essentially to catch you up to what is happening is that the server  has
threaded this process. When it receives a IOException because someone
had left the server it Excepts and then runs the finally part of the
try/catch/finally.

I don't know how prop


public void run() {

String thisLine;
try {
thisLine = br.readLine();

user = thisLine;
client.setUsername(user);
joinSend(this.user);
thisLine = br.readLine();
while (thisLine != null) {
broadcast(this.user, thisLine);

thisLine = br.readLine();
}
} catch (IOException e) {
if (debug) System.err.println("Removing
this user + :"+this.user);
} finally {
synchronized (clients) {
clients.remove(this);
partSend(this.user);
}
}
}

 
Answer #4    Answered By: Alfonso Martin     Answered On: Sep 28

create antother thread 4 each client conneciton, whenever a connection is idle
for a
predefined time(1min) this thread will send an AYT(are you there?) message. so
if
your soket has broken down, you cannot send ayt pdu from soket and this means
your client connection closed with an undefined and un controlled way.if u use
different
kinds of programming env. in your client-server model (like vbasic clients,java
servers...)
u always encounter problems like this.

so the most generic, reliable and the traditional way to check a soket
connection is AYT
messages.

 
Didn't find what you were looking for? Find more on java chat server Or get search suggestion and latest updates.




Tagged: