使用中间服务器创建对等连接 [英] Creating Peer to Peer connections using intermediate server

查看:208
本文介绍了使用中间服务器创建对等连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想连接两个客户端(通过TCP / IP套接字)。客户端可以使用中间服务器发现彼此。一旦客户端发现对方,就不应该有服务器的任何参与。



我做了一些研究,发现很多人建议 JXTA 。但是我想从头开始创建协议(因为在将来我可能需要实现相同的WebSockets(当我的客户端是一个浏览器)。目前,我的客户可以是桌面应用程序或移动应用程序。



我的问题是:


  1. 客户端如何在服务器端发现彼此?如果服务器将客户端的全局IP地址发送给彼此,那么该信息是否足以创建对等连接?


  2. 客户端具有动态IP地址,如果客户端位于同一个LAN网络,并且服务器位于不同的WAN?即使它有一个活动的套接字,他们的IP是否可以突然变化?


  3. 对等连接对于传输非连续数据是可靠的(像聊天应用程序中一样)?


[注意:通过点对点连接我的意思是建立一个客户端 - 服务器TCP / IP套接字连接(使用Java)通过将其中一个客户端作为临时套接字服务器]



提前感谢。


< 1)当客户端连接到服务器时,他们必须通知服务器他们将保持打开来自其他客户端的传入连接的端口号。服务器将知道客户端的IP地址。然后服务器将需要将这些细节传送/发送到另一方/客户端。客户的实际位置没有任何区别。如果两个客户端在同一个网络上,网络路由器将找到它们并缩短通信路径。



2)动态IP地址在活动连接期间不能更改 - 连接将被删除,并且两个客户端都必须通过服务器重新启动连接1)



3)是


I want to connect two clients (via TCP/IP sockets). The clients can discover each other using an intermediate server. Once the clients discover each other, there should not be any involvement of the server.

I made some study about this and found many people suggesting JXTA. But I'd like to create the protocol myself from scratch (because in future I might have to implement the same using WebSockets as well (when my client is a Browser)). Currently, my clients can be Desktop applications or mobile applications.

My questions are:

  1. How will clients discover each other at the server? If the server sends the global IP address of the clients to each other, will that information be enough to create a peer-to-peer connection? What if the clients are on the same LAN network and the server is on a different WAN?

  2. Client have dynamic IP address. Can their IP change all of a sudden even if it has an active socket?

  3. Is peer-to-peer connection is reliable for transfer of non-continuous data (like in chat application)?

[NOTE: by peer-to-peer connection I mean establishing a client-server TCP/IP socket connection (using Java) by making one of the client as temporary socket-server]

Thanks in advance.

解决方案

1) When the clients connect to the server they will have to notify the server of the port number they will keep open for incoming connections from other clients. The server will know client's IP address. Then the server will need to communicate/send these details to the other party/client. The actual location of the clients does not make any difference. If two clients are on the same network the network routers will find them and make their communication paths shorter.

2) Dynamic IP address can NOT change during active connection - if it does the connection will be dropped and both clients will have to re-initiate the connection through the server in 1)

3) Yes

这篇关于使用中间服务器创建对等连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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