Java Reference
In-Depth Information
protected
protected
void
void
close
() {
iif
(
clientSock
==
null
null
) {
log
(
"close when not open"
);
return
return
;
}
try
try
{
clientSock
.
close
();
clientSock
=
null
null
;
}
catch
catch
(
IOException e
) {
log
(
"Failure during close to "
+
clientIP
);
}
}
/** Send one message to this user */
public
public
void
void
send
(
String sender
,
String mesg
) {
pw
.
println
(
sender
+
SEP
+
mesg
);
}
/** Send a private message */
protected
protected
void
void
psend
(
String sender
,
String msg
) {
send
(
"<*"
+
sender
+
"*>"
,
msg
);
}
/** Send one message to all users */
public
public
void
void
broadcast
(
String sender
,
String mesg
) {
System
.
out
.
println
(
"Broadcasting "
+
sender
+
SEP
+
mesg
);
clients
.
forEach
(
sib
-> {
iif
(
DEBUG
)
System
.
out
.
println
(
"Sending to "
+
sib
);
sib
.
send
(
sender
,
mesg
);
});
iif
(
DEBUG
)
System
.
out
.
println
(
"Done broadcast"
);
}
protected
protected
ChatHandler
lookup
(
String nick
) {
synchronized
synchronized
(
clients
) {
for
for
(
ChatHandler cl
:
clients
) {
iif
(
cl
.
login
.
equals
(
nick
))
return
return
cl
;
}
}
return
return null
null
;
}
/** Present this ChatHandler as a String */