laike9m / PyPunchP2P

Python实现NAT穿透+STUN+TURN+P2P聊天 | Python P2P chat
MIT License
428 stars 168 forks source link

聊天部分怎么测试了 #5

Open colanicy opened 7 years ago

colanicy commented 7 years ago

测试已经和服务器连接,并匹配上了。 怎么测试聊天了?

colanicy commented 7 years ago

发送的信息对方收不到

laike9m commented 7 years ago

把两边完整的输出都贴出来看下

-- laike9m.com

On Fri, May 12, 2017 at 5:28 PM, colanicy notifications@github.com wrote:

发送的信息对方收不到

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/laike9m/PyPunchP2P/issues/5#issuecomment-301029586, or mute the thread https://github.com/notifications/unsubscribe-auth/ACeNzcbRaeqdRd_BHqApaxhU26gX1-hnks5r5CY_gaJpZM4NZCu9 .

colanicy commented 7 years ago

周一发上来。

colanicy commented 7 years ago

今天测试可以通了。nat配置的端口多长时间更换一次,原来的测试方式主要是ClientA发起连接,我跑到另一个地方,用ClientB响应连接,就在这个过程中就不能通讯了。应该是这段时间内通讯端口发生了变更。

laike9m commented 7 years ago

这个问题我似乎也遇到过,但是没有深入研究

colanicy commented 7 years ago

('NAT Type:', 'Full Cone') ('External IP:', '110.179.64.165') ('External Port:', 54320) (<open file '', mode 'w' at 0x0137D078>, "request sent, waiting for part ner in pool '7'...") (('118.81.97.203', 60442), 0) (<open file '', mode 'w' at 0x0137D078>, 'connected to 118.81.97.203:604 42, its NAT type is Full Cone') FullCone chat mode

为什么两个端口不一样?

colanicy commented 7 years ago

54320 和 60442 这两个端口为什么不一样了?

laike9m commented 7 years ago

额,如果我没理解错,('110.179.64.165', 54320) 是 socket 的一边,('118.81.97.203', 60442) 是另一边对吧,那端口为什么会一样?

colanicy commented 7 years ago

服务器端的信息

C:\pydev>python server.py 1234 listening on *:1234 (udp) connection from 110.179.64.165:57096 pool=1, nat_type=Full Cone, ok sent to client request received for pool: 1

客户端的信息 xiaojunping@x230:~/pydev$ python client.py 110.179.64.165 1234 1 ('NAT Type:', 'Full Cone') ('External IP:', '110.179.64.165') ('External Port:', 54320) (<open file '', mode 'w' at 0x7fab21c74150>, "request sent, waiting for partner in pool '1'...")

为什么服务器端收到的端口号是57096而不是客户端本地由stun服务器返回的54320?

laike9m commented 7 years ago

好像你的服务器和客户端都在一台机器上?那这样的话应该直接用的就是内网的port了吧

colanicy commented 7 years ago

又看了看代码,应该是新建一个socket就会分配一个新的端口号。

laike9m commented 7 years ago

哦,我想起来了,是的,因为是两个不同的 socket

colanicy commented 7 years ago

基于UDP的通信协议很难确定何时通信结束,所以NAT网关主要依赖超时机制回收外部端口。

colanicy commented 7 years ago

这个程序用的STUN版本是RFC3489还是RFC5389?

colanicy commented 7 years ago

stun.get_ip_info()函数如果返回他自己用的socket供后面通讯,那么对话使用的端口号应该就和STUN探测回来的端口一样了。

laike9m commented 7 years ago

那时候我还不知道RFC是啥,大体上是按这篇文章(Peer-to-Peer Communication Across Network Address Translators来实现的.

colanicy commented 7 years ago

我看见英文头大 @laike9m