Norbert François wrote: > I'm a beginner in C (sockets) programming, so please, excuse my stupid question. > > I'm trying to do a servent (server+client) for a p2p connexion. When I > dissociate the client and the server, everything's all right. The > Server is waiting for (pending) a connexion and when I connect on it, > I've the behaviour I want. > > But now, I tried to merge the server & client together. When I start > my program, the server is pending and the other part of my program > isn't executed :( (the server is pending in an "accept" state). I > tried to do some fork(), but it was useless (in fact, a new server is > restarted and I get a bind error). How can I solve this problem > (easily, if possible) ? You essentially have three choices: 1. Run the client and server in separate processes (i.e. fork()). 2. Run the client and server in separate threads. 3. Use select() or poll() to check that operations on sockets won't block. #1 is the easiest to implement, but it makes integrating the client and server more awkward. #2 requires being able to write thread-safe code, which can be quite complex. #3 tends to be messy, as you have to allow for the fact that read/write operations will often be incomplete, i.e. a read() may return part of a request, then the next part may not arrive until later, and you still need to service the other half (client/server) in the meantime. -- Glynn Clements <glynn@xxxxxxxxxxxxxxxxxx> - : send the line "unsubscribe linux-c-programming" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html