Stream Error
843810Nov 22 2007 — edited Nov 22 2007I am creating a simple chat, however I am running into a problem that occurs whenever a user connects.
The error is:
[10/22/2007 13:21:15] java.io.IOException: Stream closed : Stream closed
java.io.IOException: Stream closed
at java.io.BufferedReader.ensureOpen(Unknown Source)
at java.io.BufferedReader.read(Unknown Source)
at HSClient.run(HSClient.java:74)
My code is:
public HSClient(HeroServer server, Socket socket) {
this.server = server;
this.socket = socket;
this.ip = socket.getInetAddress().getHostAddress();
// --- init the reader and writer
try {
in = new BufferedReader(new InputStreamReader(socket
.getInputStream()));
out = new PrintWriter(socket.getOutputStream(), true);
} catch (IOException ioe) {
server.writeActivity("Client IP: " + ip + " could not be "
+ "initialized and has been disconnected.");
killClient();
}
}
/**
* Thread run method. Monitors incoming messages.
*/
public void run() {
try {
char charBuffer[] = new char[1];
// --- while we have an incoming stream
+(Line 74)+*while (in.read(charBuffer, 0, 1) != -1) {*
// --- create a string buffer to hold the incoming stream
StringBuffer stringBuffer = new StringBuffer(8192);
// --- while the stream hasn't ended
while (charBuffer[0] != '\0') {
// --- add the character to our buffer
stringBuffer.append(charBuffer[0]);
in.read(charBuffer, 0, 1);
}
{I know it is left open, but this is the only code related to my error.}
Any help\ideas would be greatly appreciated.
Edited by: nofilicity on Nov 22, 2007 10:36 AM