[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to spawn a server?
On Tue, Sep 10, 2002 at 11:24:55AM +0300, Jan Ekholm wrote:
> On Tue, 10 Sep 2002, Katie Lucas wrote:
>
> >On Mon, Sep 09, 2002 at 02:28:09PM +0200, Francesco Orsenigo wrote:
> >>
> >> 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?
> >
> >Why not fork, exec the server executable (which will clear out all the
> >open stuff) and then have the server open a port and have the clients
> >connect to that?
>
> fork() isn't too portable. Not if we speak Windows.
It's POSIX, most of the modern windows have POSIX support.