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

How to spawn a server?




My game works on a tight server/client system.
This means that the player usually needs to run only the client.
But when the player chooses to Host a game, the client program must create a 
server and connect to it immediatly.
At the time, the program works this way: as soon as the program is launched, 
it creates a pipe and a socketpair, then forks.
Server is controlled with the pipe, and initializes whenever needed.
When pipe is severed, the server closes.

This seems to have 2 drawbacks:
1) A latent server must be always spawned, even if it won't be used.
That should not be critical, since while latent the server does nothing.
2) pipe(), socketpair() and fork() are not very portable; alternative methods 
would require to spawn the server when is needed, and not at program 
initialization....

I was thinking to pipe(), socketpair() and then fork() only when i really 
need a server, but i don't know how does fork() works...
If I fork() a program with lots af allocated memory, low-level hardware 
access, and lots of open descriptors, all this will be copied?

Server does not need to load graphics data or access video memory, it's 
useless to have all these things up just to need to close them all...
Any idea?

Thanx in advance,
Francesco Orsenigo, Xarvh Project