我如何做一个客户端到客户端(浏览器)套接字连接? [英] How can i do a client to client (browsers) socket connection?

查看:127
本文介绍了我如何做一个客户端到客户端(浏览器)套接字连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在考虑建立一个客户端到客户端程序。但我想要的方式是使用broswer来完成它,通过一个可以建立连接的服务器来帮助。



当我需要一个unnconected套接字(或pasive)在客户端,等待连接。



我一直在考虑Html5 WebSockets,但它并没有给客户端提供一个没有连接TCP协议的套接字套接字的可能性。



我正在学习这一点,并试图找到实现这一点的方法。所有的想法都是好的:D。

解决方案

在Java applets,Flash和其他浏览器插件中可以有一个被动套接字,对于公共Web应用程序来说可能会有问题。

首先,要通过防火墙等是很困难的,您需要依赖和编写实现套接字API的浏览器插件的代码,并且把它连接到JavaScript。如果您对某些解决方案感兴趣,您可能需要查看以下堆栈溢出帖子:



浏览器之间的点对点通信的传统方法是让您的服务器充当所有连接的网关。浏览器启动连接(使用 WebSockets 或使用 XMLHttpRequest ),并始终保持与服务器的活动连接,如果丢失则重新建立连接。由于服务器应用程序总是会找到所有连接的浏览器的开放式TCP连接,因此它可以轻松地将消息路由到/从所有客户端。

I have been thinking about building a client to client program. But the way I want is to use the broswer to do it, helped by a server that can make that connection.

The troubles comes when I need to have an unnconected socket (or pasive) in a client, waiting for a connection.

I have been thinking about Html5 WebSockets, but it doesn't give to the client the posibility of having a pasive socket without connecting it with a TCP protocol.

I'm learning this and trying to find the way to do this. All ideas are wellcome :D.

解决方案

You can have a passive socket in Java applets, Flash and other browser plugins, but in general that can be problematic for public web applications.

First of all it will be difficult to get through firewalls, etc, and you'll need to depend and write code for a browser plugin that implements a socket API, and bridge it to JavaScript. If you are interested in some solutions, you may want to check out the following Stack Overflow post:

The traditional approach for peer-to-peer communications between browsers is to have your server acting as a gateway for all the connections. Browsers initiate the connection (either with WebSockets or with XMLHttpRequest) and keep an active connection to the server at all times, re-establishing it if it drops. Since the server application will always find an open TCP connection to all the connected browsers, it can easily route messages to/from all clients.

这篇关于我如何做一个客户端到客户端(浏览器)套接字连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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