简体   繁体   English

POSIX套接字VS Web套接字VS Windows TCP / IP套接字

[英]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++ . 我是网络编程的新手,对Web套接字(这是一种相当新的技术)和POSIX套接字编程 (已经存在了数十年)和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!!! 有人可以向我解释,谢谢!!!

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). C套接字API是用于创建基于流的套接字(TCP套接字,UNIX域套接字)和基于数据报的套接字(UDP套接字)的低级机制。 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). POSIX API和Windows API对此稍有不同(有时以微妙的方式……Windows具有许多POSIX功能,但有时所支持的选项或行为以微妙的,令人惊讶的方式是不同的)。

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). WebSockets是在JavaScript中使用的API,它为Web开发人员提供了一种访问此底层API的功能的方法(作为C ++程序员,您可能对此并不感兴趣)。 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. 在使用Web套接字之前,Web开发人员只能使用XMLHttpRequest(XHR)来执行请求,这需要完整的HTTP请求/响应,并且不允许较低级别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. 通过某些库,可以轻松地将HTTP(或RPC)服务器嵌入到您的应用程序中或向其他HTTP(或RPC)服务器发出请求。 For most application programmers, this is probably what you are interested in (unless you are trying to do something fancy with the networking, itself). 对于大多数应用程序程序员而言,这可能是您感兴趣的(除非您尝试对网络本身做一些花哨的事情)。

POSIX and Windows sockets is the APIs used by POSIX and Windows systems, respectively. POSIX和Windows套接字分别是POSIX和Windows系统使用的API。 The Windows socket API is modeled after the POSIX (previously BSD) API so they are sharing a lot of functions. Windows套接字API是根据POSIX(以前为BSD)API建模的,因此它们共享许多功能。 The APIs can be used from both C and C++. 这些API可以在C和C ++中使用。

Websockets is something completely different, and is actually a protocol on top of TCP (but uses HTTP for the initial handshake). Websocket是完全不同的东西,实际上是TCP之上的协议(但使用HTTP进行初始握手)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM