0

I'm new to socket programming and want to make a cross platform app (C++) that supports both windows and unix systems.

The default on for websocket transport on Windows seems to be windows sockets while on unix systems it's BSD sockets. So how can I decide at preprocessor time which sockets are available so I can abstract away this layer? Is there a definition which I can check which also corresponds to the availability of these features?

I thought about checking the _WIN32 and __unix__ definitions but those are platform definitions and I'm not sure if they necessarily correspond to the availability of a feature. I guess this is very well the case for Windows systems but I heard that some unix systems will only offer partial BSD socket compliance so this check could be misleading?

glades
  • 3,778
  • 1
  • 12
  • 34

1 Answers1

0

I'm new to socket programming and want to make a cross platform app (C++) that supports both windows and unix systems.

There are numerous cross-platform socket libraries that are already available.

The default on for websocket transport on Windows seems to be windows sockets while on unix systems it's BSD sockets.

Winsock includes BSD-compatible socket functions that are mostly API-compatible with other platforms (there are some differences). The biggest difference you will have to deal with is in the header files that you will need to #include on each platform.

Is there a definition which I can check which also corresponds to the availability of these features?

No, there is not.

I thought about checking the _WIN32 and __unix__ definitions but those are platform definitions and I'm not sure if they necessarily correspond to the availability of a feature.

That is basically what you need to do (and what other cross-platform libraries do).

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • Thank you! Idk it would need to be a really lightweight library. Is there such a one? – glades Nov 09 '22 at 06:57
  • I'm sure there are. But asking for library recommendations is [off-topic](https://stackoverflow.com/help/on-topic) for StackOverflow. Just search around until you find something that suits your needs. – Remy Lebeau Nov 09 '22 at 22:44