html5的websocket可以通过浏览器监听端口吗?
我是 html5 的新手,
我发现 html5 支持 websocket,我对此有一些问题,
有什么方法可以创建从一个浏览器到另一个浏览器的连接吗?
就像socket.io 的服务器监听我的浏览器上的端口一样?
var io = require('socket.io').listen(80);
io.sockets.on('connection', function (socket) {
socket.emit('news', { hello: 'world' });
socket.on('my other event', function (data) {
console.log(data);
});
});
I newbee to html5
I find that html5 support the websocket and i have some problem with it
is there any way to create a connect from one browser to an other browser?
like socket.io's server listten a port on my browser?
var io = require('socket.io').listen(80);
io.sockets.on('connection', function (socket) {
socket.emit('news', { hello: 'world' });
socket.on('my other event', function (data) {
console.log(data);
});
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
即使您设法监听端口,这也还不够,因为 P2P 通信比这更复杂。它包括 NAT 穿越,这是一个复杂的主题,需要中央服务器来促进通信。
与 Remy Lebeau 所说的相反:P2P 可以包括通过服务器进行。这称为 TURN,它已在早期 P2P 系统中使用多年。
Even if you managed to listen to a port, this would not be enough, because P2P communication is more complicated than that. It includes NAT traversal which is a complex subject requiring a central server to facilitate communication.
Contrary to what Remy Lebeau says: P2P can include going via a server. This is called T.U.R.N. It has been used for years in early P2P systems.
不是直接浏览器到浏览器,需要通过服务器。
为什么不使用socket.io?
Not directly browser to browser, it needs to go through a server.
Why not use socket.io?