On Apr 22, 9:33 pm, Esmond Pitt <esmond.p...@nospam.bigpond.com>
wrote:
SadRed wrote:
On Apr 23, 7:59 am, Chris <cc_brews...@yahoo.com> wrote:
public void run() {
System.out.println("Server ready.");
int i = 1;
System.out.println("Start of ");
try {
System.out.println("Start of connecting section. i = " +
i);
// *** EXECUTES CORRECTLY TO HERE
ServerSocket ss = new ServerSocket(port);
You are re-creating the same server socket each time
new client is created.
Absolute rubbish. He isn't.
Chris, your code is mostly fine except that you should always close
output streams of a socket before the input, and in fact once you've
done that closing the input stream or the socket is redundant. I also
don't know why you're starting the client thread and then immediately
interrupting it - don't do that.
Your problem is coming when restarting the server. Use new
ServerSocket(), then call serverSocket.setReuseAddress(), then
serverSocket.bind() to get around this.
Does this apply even when I've just started the program? Because I get
an error on the first time. Also, since my "new ServerSocket"
statement is what causes the error, your other calls wouldn't affect
it if they came after it. One more question: I don't understand the
argument type for bind() -- it won't take the port number I'm using.
Thanks for your help.
going on.