4

I have the impression that sockets are just one of several ways that an application can communicate over the internet, maybe because of the wording in some tutorials I have read recently where it seems like sockets have been chosen as the most efficient tool out of many for the job.

Is this assumption right or do all networking applications use sockets on some level?

Edit: To clarify I'm looking for a practical answer. If I want to write some client/server program that will run on two of my computers running either Linux or Windows, should I always think sockets first (or higher level protocol that uses sockets), or are there other equivalents that may be better suited for the job than sockets.

Q-bertsuit
  • 3,223
  • 6
  • 30
  • 55
  • 2
    Sockets are an API construct. If you want to spew raw packets to the NIC's API then you're free to do so. – CodeCaster Dec 13 '17 at 13:44
  • 1
    Why do you ask? Do you need a practical answer, or an exhaustive one? Some weird OSes don't have sockets but provide some other API for TCP/IP? What computer and operating systems do you have in mind? – Basile Starynkevitch Dec 13 '17 at 13:59
  • @BasileStarynkevitch Please see my edited question – Q-bertsuit Dec 13 '17 at 15:25
  • But you don't tell the most important: what concrete operating system do you want your code to run on? – Basile Starynkevitch Dec 13 '17 at 15:33
  • 1
    Also, what kind of computers do you own? A Linux desktop, or a supercomputer, is not the same as an Arduino – Basile Starynkevitch Dec 13 '17 at 15:41
  • [Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.](http://meta.stackoverflow.com/questions/254393) –  Dec 13 '17 at 15:49
  • 2
    Please read [What types of questions should I avoid asking?](http://stackoverflow.com/help/dont-ask) before attempting to ask more questions. –  Dec 13 '17 at 15:49
  • I run Ubuntu on one machine, Windows 10 on another, I have Raspberry Pies and an Arduino with an ethernet shield, so if there are important specifics to those combinations I would be interested in knowing about it! – Q-bertsuit Dec 13 '17 at 15:50
  • It is more operating system (or library) specific than hardware specific. You need to dive into documentation (I don't know how Arduino uses Ethernet). Some computers don't have a familiar OS. – Basile Starynkevitch Dec 13 '17 at 15:52
  • 1
    Microsoft Windows has always had non-socket networking APIs, even to this day with e.g. .Net TCPListener and TCPClient classes. – President James K. Polk Dec 13 '17 at 16:34
  • @JamesKPolk: Is .Net `TCPListener` usable from a C program? Berkeley sockets are for C mostly (and for many implementations above C). – Basile Starynkevitch Dec 13 '17 at 17:07
  • 1
    Socket APIs that are reasonably faithful to "Berkeley" sockets are available in most high-level languages including Java and python. I suspect that most if not all of those eventually end up using native code calls to the system socket library. And C++ code on Windows can make use of .Net classes. – President James K. Polk Dec 13 '17 at 17:48
  • 1
    "*do all networking applications use sockets on some level?*" - **Internet** apps do, yes, since sockets are primarily how apps gain access to IP protocols like TCP and UDP. **Networking** apps, maybe, depending on the OS and networking protocol used. Protocols other than TCP/UDP can be used on a local network (IPX, NetBIOS, SMB, etc), and they are not all accessed using socket APIs – Remy Lebeau Dec 14 '17 at 02:45

1 Answers1

3

It is operating system specific. Some (old, or academic) OSes provide weird APIs for TCP/IP, and some OSes don't even do any networking. IIRC, Gnu Hurd has something else than sockets (and probably Fuschia also has something else).

In practice, Berkeley sockets are nearly a de facto standard (this was not always the case, e.g. TLI), at least on Unix-like and POSIX systems (and probably on Windows also) and when programming in C (or related stuff, notably C++).

And you could use higher-level libraries, e.g. MPI, 0mq, or protocol specific libraries (for HTTP, libcurl on client side, libonion on server side, ....) etc ..... They are generally built above sockets.

do all networking applications use sockets on some level?

On some supercomputers, you can also have InfiniBand (and perhaps a variant of MPI using that hardware without sockets, but with something else). etc... Sometimes they have some InfinBand specific address family for socket ....

(It is more than ten years that I didn't access any supercomputer, so I could be wrong for the details)


BTW, some consortia like FIWIRE or AUTOSAR define their own networking APIs (for niche markets or specific industries).

(perhaps such consortia are defining an API above sockets; I don't know them well enough; you need to check)

See also the libraries mentioned near the end of this answer.


If I want to write some client/server program that will run on two of my computers running either Linux or Windows, should I always think sockets first (or higher level protocol that uses sockets),

Certainly yes in practice. And I would often consider using some existing free software library above Berkeley sockets.

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547