Networking and the BSD Sockets API
Subject:   Address in use
Date:   2002-12-29 17:44:43
From:   johnts
Response to: Address in use

Got it to work, using code from Beej's Guide page mentioned in another post - there was the exact description of the problem too. I added:

int yes=1;
if (setsockopt(listenfd,SOL_SOCKET,SO_REUSEADDR,&yes,sizeof(int)) < 0) {
perror( "setsockopt" );

and I can start the server application right after stopping it without an error.