简体   繁体   English

Socket.io可以连接到什么?

[英]what can Socket.io connect to?

I'm playing around with an open source project that uses Socket.IO to connect to the website chat.meatspac.es which is hosted on a different server. 我正在玩一个开源项目,该项目使用Socket.IO连接到托管在不同服务器上的chat.meatspac.es网站。 It connects like this 它像这样连接

var socket = socketClient.connect('https://chat.meatspac.es');

And then it listens for the data that is also published on chat.meatspac.es . 然后它会侦听也在chat.meatspac.es发布的数据。 Does this only work because the chat.meatspac.es is also a Socket.IO application and it's emitting signals that can be picked up by this other open sourced project? 这是否有效,因为chat.meatspac.es也是一个Socket.IO应用程序,它发出的信号可以被其他开源项目选中?

For example, I naively tried to connect to my Twitter stream 例如,我天真地尝试连接到我的Twitter流

 var socket = socketClient.connect('https://twitter.com/username');

but it wouldn't listen for messages published in my Twitter feed. 但它不会收听我的Twitter Feed中发布的消息。

So, my question is, can Socket.IO only connect to servers that are emitting Socket.IO messages? 所以,我的问题是,Socket.IO只能连接到发出Socket.IO消息的服务器吗?

socket.io allows simulation of socket API (used in traditional desktop apps) for access with javascript (web). socket.io允许模拟socket API(用于传统的桌面应用程序)以便使用javascript(web)进行访问。

But this is will not behave exactly as traditional sockets behave. 但这不会像传统套接字那样完全表现。 It uses HTML5 websockets for sockets simulation 它使用HTML5 websockets进行套接字模拟

Sockets.io needs to have a compatible server app, that is shown here by deploying a server app using nodejs Sockets.io需要有一个兼容的服务器应用程序, 这里通过使用nodejs部署服务器应用程序来显示

Take a look at server side implementations of websockets today, socket.io with nodejs being one of them. 今天看一下websockets的服务器端实现,socket.io,其中nodejs就是其中之一。 http://www.html5rocks.com/en/tutorials/websockets/basics/ http://www.html5rocks.com/en/tutorials/websockets/basics/

So for your question using socket.io to create a socket connection to twitter: 因此,对于使用socket.io创建与twitter的套接字连接的问题:

var socket = socketClient.connect('https://twitter.com/username');

This is not possible because socket.io is not a real socket API, its just a simulation of sockets api using HTML5 websocket api and maybe other fallbacks (long polling, comet, etc). 这是不可能的,因为socket.io不是一个真正的套接字API,它只是使用HTML5 websocket api和其他回退(长轮询,彗星等)的套接字api的模拟。 So the server should be compatible to handle the ws(websocket protocol) request and in case of twitter here to get feed stream, this is not the case so this can not be done like that. 所以服务器应该兼容处理ws(websocket协议)请求,并且如果twitter在这里获得feed流,情况并非如此,所以不能这样做。

See the twitter api to programmatically get access to twitter resources 查看twitter api以编程方式访问twitter资源

https://dev.twitter.com/docs/api/1.1 https://dev.twitter.com/docs/api/1.1

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

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