Socket programming

This is rather a general quick question. But like C #, Python, C, C ++ ......., etc.

All major Socket networking programs are essentially the same. Like all of them use Berkley Sockets (I think they are called), or each language has its own way of creating sockets.

thanks

+4
source share
4 answers

Sockets are platform dependent, not language dependent. Thus, linux uses only BSD sockets, Windows offers both BSD sockets (used almost exclusively) and M $ socket nodes (called WSA), and not others. All this boils down to what's under the hood - more precisely, at the kernel level of the OS. The socket implementation implemented there will offer the first set of APIs to make them available for kernel / user space - usually through a common object-dynamic linked library and, thus, โ€œnativelyโ€ supports c / C ++ languages. All other languages โ€‹โ€‹rely on language-specific bindings to those SO / DLL files offered by the OS initially for C / C ++.

NTN

+3
source

Sockets are basically the same in C, C ++, Java, Ruby. They are a little easier (because the assembly of classes processes the boiler plate) in higher-level languages. If you can write Socket code in C, you can do it anywhere if you have a translation link.

@Kellogs brings up a good point, Windows has its own Socket API, which (as a rule) works better (in my experience) on Windows than the proposed Posix implementations. The APIs are very similar. I would make an analogy of OpenGL with DirectX. If you really know one, then you can find another link.

+1
source

Currently, we do not distinguish between a language, a class library, which can be accessed from the language and the underlying operating system. Here is my explanation

C, C ++, C #, Java - only languages โ€‹โ€‹do not have specific support regarding network programming.

Java class library, .NET Framework, C ++ standard library - among them, I believe that C # and Java provide some classes for network programming. The C ++ standard library does not provide network programming classes (only iostreams are available for file, stdinput and strings). But the BOOST library for C ++ provides classes for network programming. I do not know other libraries.

OS The operating system provides a basic api (mainly in C), which is used by the above class libraries. In the case of windows, this is the winsock api (WSA), and in the case of unix, this is the BSD api socket. I think windows also support, to some extent, BSD api, so the learning curve is less. But as @EnabrenTane said it is more than that.

0
source

Agree with the above kellogs. Windows and most major POSIX-compatible operating systems support the base BSD API. In addition to the Berkeley socket, each platform provides an additional proprietary API for increased performance and scalability. These advanced APIs are not limited to sockets only - they work with any I / O operations (i.e., disk files, named pipes, etc.). For example, (in addition to the traditional select () and poll ()) Linux has its own epoll mechanism, BSD has kqueue, Windows has WSAevent *, WSAaAsync *, and I / O completion APIs. These differences are mainly visible in lower level languages โ€‹โ€‹such as C, C ++ or Pascal.

C #, Java, Python, Ruby et al. are "higher level" than C - they provide reliable technology to isolate you from low-level APIs. Instead of directly using bare-bones socket APIs, you can use the extensive runtime class libraries provided with each platform. For example, to write a TCP / IP server in Python, you can simply use the SocketServer class. Similarly, in C # you can use WebClient to downlad files on the network. In C ++, you have the Boost library. Of course, nothing prevents you from using the raw socket API directly in your application.

0
source

Source: https://habr.com/ru/post/1333656/


All Articles