插座和WebSocket的区别? [英] Difference between socket and websocket?

查看:192
本文介绍了插座和WebSocket的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立web应用程序需要使用套接字连接另一个应用程序通信。这对我来说是一个新的领域,所以要确保<一href=\"http://stackoverflow.com/questions/152457/what-is-the-difference-between-a-port-and-a-socket\">sockets比<不同href=\"http://stackoverflow.com/questions/4363899/making-moves-w-websockets-and-python-django-twisted\">websockets.好像他们只是概念上相似。

I'm building web app that needs to communicate with another application using socket connections. This is new territory for me, so want to be sure that sockets are different than websockets. It seems like they're only conceptually similar.

问,因为最初我计划上使用Django为我的项目的基础,但在SO后我联系到它上面的十分清楚地表明的WebSockets是不可能的(或至少是不可靠的,甚至像使用$ p $的Django的WebSockets)pferred Django的设置(阿帕奇与mod_wsgi的)。然而,我发现其他职位,随便导入Python的插座模块的<一个简单的东西href=\"http://stackoverflow.com/questions/4093999/how-to-use-django-to-get-the-name-for-the-host-server\">grabbing服务器的主机名。

Asking because initially I'd planned on using Django as the foundation for my project, but in the SO post I linked to above it's made very clear that websockets aren't possible (or at least not reliable, even with something like django-websockets) using the preferred Django setup (Apache with mod_wsgi). Yet I've found other posts that casually import Python's socket module for something as simple as grabbing the server's hostname.

所以:


  • 难道真有什么不同?

  • 有什么理由不使用Django的依赖与外部服务器建立套接字连接的一个项目?

推荐答案

要回答你的问题。


  1. 尽管他们实现(一般)类似的事情,后,他们的真的不一样。典型的WebSockets从浏览器中运行连接到应用服务器过类似的协议 HTTP 运行在 TCP / IP 。因此,他们主要是为那些需要它的服务器永久连接Web应用程序。而另一方面,普通插座更强大和通用。他们跑过来的 TCP / IP 但不限于浏览器或 HTTP 的协议。它们可以被用来实现任何类型的通信。

  2. 没有。没有理由。

  1. Even though they achieve (in general) similar things, yes, they are really different. WebSockets typically run from browsers connecting to Application Server over a protocol similar to HTTP that runs over TCP/IP. So they are primarily for Web Applications that require a permanent connection to its server. On the other hand, plain sockets are more powerful and generic. They run over TCP/IP but they are not restricted to browsers or HTTP protocol. They could be used to implement any kind of communication.
  2. No. There is no reason.

这篇关于插座和WebSocket的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆