Winsock CreateProces()

Started by
11 comments, last by Nik02 18 years, 7 months ago
There is no equivalent of fork() on Win32, so you will have to work out an alternative.

Because fork() based servers on Unix often share objects like sockets or other file descriptors with their parents, CreateProcess() on Win32 is not really a suitable replacement (maybe you can share sockets with the parent, but it's not straightforward).

Therefore, win32-based servers usually use threads instead of processes.

But you can create a server on win32 or Unix without using fork() or creating new processes or threads, by just using nonblocking sockets. This is probably the best way to do it while you're playing around, as it creates the easiest program to understand (only one part of the program can be executing at once)

Of course setting up the data structures for the nonblocking sockets is more tricky, but once you've done it it will work fine. (There are loads of examples anyway).

You'd normally use one of
select() (Unix or win32)
WaitForMultipleObjects() (win32)
poll() (Unix)
WSAAsyncSelect(win32, if you use a Windows message loop)

Mark
Advertisement
Yeah I readed something about the select aswell in beej's tutorial. But maybe I'll just stick with CreateThread(). CreateThread only requires 6 arguments and is much easier to use than CreateProces() in my opinion.

Thanks alot everyone,
Toadhead
Quote:Original post by Toadhead
Yeah I readed something about the select aswell in beej's tutorial. But maybe I'll just stick with CreateThread(). CreateThread only requires 6 arguments and is much easier to use than CreateProces() in my opinion.

Thanks alot everyone,
Toadhead


Microsoft actually recommends this approach, as threads are much more efficient than new processes for each client.

I hope your project works out fine [smile]

Niko Suni

This topic is closed to new replies.

Advertisement