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

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

问题描述

我正在构建需要使用套接字连接与其他应用程序通信的Web应用程序。这对我来说是一个新的领域,所以要确保套接字 websockets 不同。它似乎只是在概念上相似。要求,因为最初我计划使用Django作为我的项目的基础,但是在SO链接到上面的这篇文章中,非常清楚的是,Websockets不是使用首选的Django设置(具有mod_wsgi的Apache)可能(或至少不可靠,甚至使用类似django-websockets的东西)。然而,我发现其他帖子,随便导入Python的套接字模块,只要简单的抓取服务器的主机名



所以:




  • 他们真的不同吗?

  • 有没有任何理由不使用Django来依赖于与外部服务器建立套接字连接的项目?


解决方案

回答您的问题。


  1. 即使他们(一般)实现了类似的东西,,他们真的不同。 WebSockets通常通过类似于运行在 TCP / IP HTTP 的协议从连接到应用服务器的浏览器运行。因此,它们主要用于需要永久连接到其服务器的Web应用程序。另一方面,普通插座更加强大和通用。他们运行 TCP / IP ,但不限于浏览器或 HTTP 协议。它们可以用于实现任何类型的沟通。

  2. 不。没有理由。


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.

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.

So:

  • Are they really different?
  • Is there any reason not to use Django for a project that relies on establishing socket connections with an outside server?

解决方案

To answer your questions.

  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天全站免登陆