Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Using a socket array (Java)

Name: Anonymous 2007-06-23 13:07 ID:ghqoDeg/

I'm brand new to Java and have been working with it for, at the max, 3 hours. I've got a C background.
Anyway, I'm using it for a multi-threaded socket server and need to be able to access all the connected clients' sockets. I figured this would be achieved through creating a socket array and then assigning each socket object, as it's created, to whatever spot in the array is open. This part goes fine. However, when I try to access the methods of the socket, I get thrown a screenful of errors:
java.net.SocketException: socket closed
        at java.net.SocketInputStream.socketRead0(Native Method)
        at java.net.SocketInputStream.read(Unknown Source)
        at sun.nio.cs.StreamDecoder.readBytes(Unknown Source)
        at sun.nio.cs.StreamDecoder.implRead(Unknown Source)
        at sun.nio.cs.StreamDecoder.read(Unknown Source)
        at java.io.InputStreamReader.read(Unknown Source)
        at java.io.BufferedReader.fill(Unknown Source)
        at java.io.BufferedReader.readLine(Unknown Source)
        at java.io.BufferedReader.readLine(Unknown Source)
        at SocketThreader.run(SocketThreader.java:41)

I'm trying to use the objects with this:
for (int i = 0; i < MultiSocket.maxClients; i++)
{
    if (MultiSocket.clientsockets[i] != null && i != clientid)
    {
        PrintWriter tmpout = new PrintWriter(MultiSocket.clientsockets[i].getOutputStream(), true);
        tmpout.println("Remote msg: " + outputLine);
        tmpout.close();
    }
}

Any help on this would be appreciated, as I can't find any documentation on socket arrays.

Name: Anonymous 2007-06-24 3:35 ID:WOkO2AuW

Why not just check if the string is empty? Is it what you're really after, or do you really want to check against null?

String blah;
// ...
if (blah.equals("")) {
  System.out.println("blah is empty");
} else {
  System.out.println("blah is not empty");
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List