[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Checking Ports? (fwd)



On Mon, Jun 08, 1998 at 01:54:40PM +0100, David Wright wrote:
> I run a very simple joystick server that writes its position to a port, say,
> 50005, so that (a) multiple clients can connect to the stick (b) I can run
> a fake server on machines without a stick and continue to test programs that
> need to read a stick.
> 
> When I kill the server, I find I often can't restart it on that port, but
> can on, say, 50006. I'm guessing that some resource stays around until it's
> killed off, usually after less than a minute.
> 
> I intend making my server pick the next free port, and likewise the clients
> will have to play chase the server. Meanwhile I don't worry.

You need to set the socket to be reusable, eg:

            int fd, on = 1;
            [...]

            /* Set it to be re-usable */
            if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR,
                (char *) &on, sizeof(on)) < 0) {
                fprintf(stderr, "Could not set socket options\n");
            }



Hamish
-- 
Hamish Moffatt, hamish@debian.org, hamish@rising.com.au, hmoffatt@mail.com
Latest Debian packages at ftp://ftp.rising.com.au/pub/hamish. PGP#EFA6B9D5
CCs of replies from mailing lists are welcome.   http://hamish.home.ml.org


--
To UNSUBSCRIBE, email to debian-user-request@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org


Reply to: