Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

POSIX socket VS Web Socket VS Windows TCP/IP Socket

I am new to network programming and am confused over Web Sockets which seems to be a fairly new technology and POSIX Socket Programming which has been around for decades and Windows TCP/IP Socket C++.

What exactly is the difference between them ??? , it looks to me as though all three are the same as its all a socket connection between client and server. Can someone explain to me , thanks!!!

like image 218
Computernerd Avatar asked Nov 05 '25 07:11

Computernerd


1 Answers

The C sockets API is the low-level mechanism for creating stream-based sockets (TCP sockets, UNIX domain sockets) and datagram-based sockets (UDP sockets). The POSIX API and the Windows API for this are slightly different (sometimes in subtle ways... Windows has many of the POSIX functions, but sometimes the supported options or the behaviors are different in subtle, surprising ways).

WebSockets is an API for use in JavaScript that provides web developers with a means of accessing the power of this low-level API (and is something that is probably not of interest to you as a C++ programmer). Prior to web sockets, web developers could only use XMLHttpRequest (XHR) to perform requests, which required a full-blown HTTP request/response and didn't allow for the same kind of persistent connections and light-weight communications of the lower level API.

Now, in terms of what you should actually do as a developer, you probably want to reuse an existing library for any sockets programming. There are libraries that make it easy to embed an HTTP (or RPC) server into your application or to issue requests to other HTTP (or RPC) servers. For most application programmers, this is probably what you are interested in (unless you are trying to do something fancy with the networking, itself).

like image 81
Michael Aaron Safyan Avatar answered Nov 08 '25 13:11

Michael Aaron Safyan