socket system call can not succedd right after application crash.

hello all,

I have developed a server application in C for ulinux kernel 2.6.It works very fine; creating a socket, binding it to a port, listening for incoming sockets and accepting them ,all finish without any error.
But there is a problem regarding application crash.After an intentionally termination of the application(Ctrl+C) or the application crash( by whatever reason it might be ) , when i run the application for the next time -right after application ending-, the socket creation stage fails for about 10" or more.After a while, the socket creation will succeed and everything starts normally.My question is why the socket creation cannot proceed?Is it because of still opened sockets from clients? it is because of underlying OS mechanism?

It's a socket thing, you'll have to tell the OS that the socket may be used more than once. A nice explanation of socket programming and the associated options can be found here (Main page)

Also, it might be a good idea to set up a signal handler for SIGINT, SIGTERM, ..., which cleans up the workspace (close sockets, free() memory, ...) if your program dies.