Problem closing sockets

W

Will

I have a client and a server, the server executes bind(), receives data,
and then I close() the file descriptor. In the client side I
connect(), send() data and close() the file descriptor also.

Everything works fine, but when I restart the server it gives me an
error in bind, the error description is "Address already in use" or
something like that, and it works just fine about a minute after I first
close the socket.

Any idea of how to close the socket without keeping the address used?
 
C

Chris McDonald

Will said:
I have a client and a server, the server executes bind(), receives data,
and then I close() the file descriptor. In the client side I
connect(), send() data and close() the file descriptor also.
Everything works fine, but when I restart the server it gives me an
error in bind, the error description is "Address already in use" or
something like that, and it works just fine about a minute after I first
close the socket.
Any idea of how to close the socket without keeping the address used?


<NOTHING-TO-DO-WITH-STANDARD-C-HERE>

int opt = 1;

setsockopt(server_sd, SOL_SOCKET, SO_REUSEADDR, (char *)&opt, sizeof(opt));

</NOTHING-TO-DO-WITH-STANDARD-C-HERE>
 
N

Neroku

Will ha escrito:
I have a client and a server, the server executes bind(), receives data,
and then I close() the file descriptor. In the client side I
connect(), send() data and close() the file descriptor also.

Everything works fine, but when I restart the server it gives me an
error in bind, the error description is "Address already in use" or
something like that, and it works just fine about a minute after I first
close the socket.

Any idea of how to close the socket without keeping the address used?

This is off-topic here, we only discuss the standard C language, a
better place to ask would be comp.unix.programmer.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,042
Latest member
icassiem

Latest Threads

Top