Link to home
Start Free TrialLog in
Avatar of Chris1078
Chris1078

asked on

Sockets portability

I am writing a sockets class to be the communications backbone for a distributed application.  I'm getting conflicting information on the portability of winsock.  Some of my information says that it is fully portable, while other implies it is a windows-only thing.  I need to be able to port code from a win-nt development enviroment to run on a power-pc.  I'm accustomed to letting the JVM take care of all this stuff for me, so I'm kinda lost.  Thanks for your help.
ASKER CERTIFIED SOLUTION
Avatar of wkmatt42
wkmatt42

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Chris1078
Chris1078

ASKER

Eventually, it will be running integrity OS.
The WINSOCK sockets library is a pretty good approximation of the Berkeley sockets library more common to unix systems.  It is NOT, however, a 100% compatible library.  There are some features missing or slightly different between the two.  It is, however, possible to account for these in preprocessor directives and so on to be able to have a single source for a multi-platform sockets package.  Be aware, as mentioned above, that the WINSOCK ASYNC calls, those starting with WSA, have NO counterpart in a Berkeley sockets library.  Also be aware that blocking sockets are not usually a concern on unix since it's common to use fork() for such calls.  Since Windows has no fork() counterpart, this can be a significant design issue for you.
In regards to the fork comment above:
I've used fork, but isin't there a "create process" or some such command for windows?  I believe it dosen't create an exact copy like fork, but allows you to create a seperate thread of execution.  Anybody know about that?  I had been planning on using fork down the road in development until jhance's comment reminded me there is no such thing on windows.  From my understanding Integrity is kind of an obscure OS, but does anyone know about using sockets on it?
Windows CreateProcess is not fork().  Windows CreateThread is also not fork().  

fork() just does not have a counterpart in Windows...

CreateProcess creates a NEW PROCESS.  If you are familiar with the system() function, you basically understand what CreateProcess does.  It starts a new program.

CreateThread create a NEW THREAD in the same process.  The thread shares everything with other threads in the same process EXCEPT its stack.

fork() does something else entirely.  It creates a new "thread" like CreateThread but, and this is a big but, the entire environment from the process that called fork() is duplicated for the child process/thread.  It's like a new process but also like a thread.  So it literally FORKS the running process into two identical processes.  The only way to tell who you are is the value return by the fork() function.  It's a PID for the parent (i.e. the original caller of fork) but it's NULL for the child, the duplicate process.
Yes, I realize that there is no windows fork.  I'm not asking for a "winfork"...I'm asking if CreateThread (not CreateProcess, couldn't remember the name) will allow me to create a seperate thread of execution that I can use to let a blocking socket run in while the main thread of execution continues and can simply check the newly created thread for messages when needed?  
Avatar of Axter
listening...
I can't imagine why not. I do pretty much the same thing for a server app on a unix box and it's been running for about two years.