Solved

Sockets portability

Posted on 2001-07-03
8
345 Views
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.
0
Comment
Question by:Chris1078
  • 3
  • 2
  • 2
  • +1
8 Comments
 

Accepted Solution

by:
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?
0
 

Author Comment

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

Expert Comment

by:jhance
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.
0
 

Author Comment

by:Chris1078
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?
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 32

Expert Comment

by:jhance
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.
0
 

Author Comment

by:Chris1078
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?  
0
 
LVL 30

Expert Comment

by:Axter
ID: 6251115
listening...
0
 

Expert Comment

by:wkmatt42
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.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

760 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

16 Experts available now in Live!

Get 1:1 Help Now