Sockets portability

Posted on 2001-07-03
Last Modified: 2010-05-18
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.
Question by:Chris1078
  • 3
  • 2
  • 2
  • +1

Accepted Solution

wkmatt42 earned 50 total points
ID: 6249880
Anything function that starts with WSA is not portable. Functions like socket(), accept(), bind(), connect(), etc. should be, though the header files you'll need to include will likely vary.

What OS is running on the power-pc?

Author Comment

ID: 6249944
Eventually, it will be running integrity OS.
LVL 32

Expert Comment

ID: 6249949
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.
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.


Author Comment

ID: 6249993
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?
LVL 32

Expert Comment

ID: 6250101
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.

Author Comment

ID: 6250316
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?  
LVL 30

Expert Comment

ID: 6251115

Expert Comment

ID: 6253337
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.

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

815 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now