Well I have been wondering if there is a standard socket header file for C++
I did search the whole internet (using google search engine ), but couldn't find any standard socket header file for C++ , beside finding some libraries, like Boost, chilkat etc...
I have only succeeded in finding a standard socket header file for C programming language. If I used the C standard socket header file, but inside my C++ code, does it mean my program is Pure C++ or C and C++?
Because I didn't find any standard C++ socket header file. Like
there is <string>
for C++ and there is <string.h>
for C, but there is no socket
standard header file for C++.
I hope someone C/C++ wise would explain all that for me, step by step.
There is no standard socket library in C++. You can either use whatever sockets API your operating system provides (typically a C API, on Unix operating systems it would be the BSD sockets API), or you can use a C++ library like Boost.ASIO, which is cross-platform.
BSD sockets, invented by Bill Joy back in the 70's, is arguably the "standard sockets API".
Typically, you'd include the following headers:
#include <sys/socket.h> // Core BSD socket functions and data structures.
#include <netinet/in.h> // AF_INET and AF_INET6 address families and their
// corresponding protocol families PF_INET and PF_INET6.
#include <arpa/inet.h> // Functions for manipulating numeric IP addresses.
#include <netdb.h> // Name resolution
Beej's Guide is an excellent tutorial on sockets (BSD sockets) programming:
http://beej.us/guide/bgnet/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With