How do you close your program?  If you just "ctrl-c" it, the socket is not
closed properly.  You need a way to tell the server to stop listening
(setting your listening variable to false) and it will be fine.

bye,
Sophie Benoit

-----Original Message-----
From: Zhihong Pan [mailto:[EMAIL PROTECTED]]
Sent: Monday, April 02, 2001 1:56 PM
To: [EMAIL PROTECTED]
Subject: java socket port


Hi,

I have a problem with my java ServerSocket. At first I created a
ServerSocket at port 34567. I run the program, it works fine. Then I stopped
the server, and edit and recompile the program. If I run it again, I got the
following IOException error message:" Adddress already in use". So I have to
change port number each time I want to modify my code. But if I run my code
on window, I didn't get any problem. I append my code below. Can anybody
help me ? 

Thanks in advance.

Zhihong Pan
Chek, Inc


public class MyServer {

    public static void main(String[] args) throws IOException {

        ServerSocket serverSocket = null;
        boolean listening = true;

        try {
            serverSocket = new ServerSocket(34567);
        } catch (IOException e) {
            System.out.println(e.getMessage());
            System.exit(-1);
        }

        while (listening)
             new MyServerThread(serverSocket.accept()).start();

        serverSocket.close();
    }
}



----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]


----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to