Connecting child processes to the server

I try to fork child processes and they connect to a server.
At the beginning, I create a socket(1 socket for all child processes), after that at each child process I connect to the server using connect function but I get this error msg:"Transport endpoint is already connected"

but if I create a socket for every child processes and connect the child processes to the server, I get no error.

if the memory space of the parent is copied, why this problem occurs?what is the difference between the two methods?

hi..
could you plz mention which OS(Linux / Solaris/Unix) are you using?
most of the implementations use COW (copy on write) philosophy.
when you fork they use the same process address space but when you go ahead and modify the data in their address spaces they create a separate copy for the entire space and pass the control into that.
In your case if you create the 1 socket for all the children then the children seem to be using the same the socket descriptor as long as you dont modify(that you are not )
but in the latter case when you create new sockets for each of the children then possibly they are getting their own copy of address spaces and so they are connecting to the server independantly.
Hope this helps.
regards
ttyl

thanks.I got it.by the way,I have a linux box.