在公共Internet上使用套接字的视频聊天应用程序 [英] Video chat application using socket over public Internet

查看:94
本文介绍了在公共Internet上使用套接字的视频聊天应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发Java视频聊天应用程序.我使用Java套接字进行通信.但是似乎我必须设置确切的IP和端口才能连接套接字服务器.我的设计是:

I am developing a Java Video chat application. I use Java socket to communicate. But it seems I have to set up the exact IP and Port to connect a socket server. My design is:

  1. 两个客户端注册器都向服务器报告其ip,然后服务器交换其信息.
  2. 选择一个客户端(A)作为视频聊天套接字服务器,并将其ip和端口报告给服务器.服务器将告诉另一个客户端(B)他的视频聊天服务器的IP和端口.
  3. 客户端B向客户端A注册自己.现在,客户端A和客户端B可以直接进行通信了.

问题来了.如果A具有公共Internet IP,则一切正常.问题是,如果客户端A和客户端B都在路由器后面,例如客户端A和客户端B在不同的大学中,它们如何与套接字通信?

Here comes problem. If A has a public Internet IP, things work well. Problem is that if client A and B are both behind a router, for example client A and B are in different University, how can they communicate with socket?

推荐答案

嗯,这里有一些含义

1.您必须在路由器(NAT)中打开端口,以便它知道正在侦听该端口的PC/设备的IP.您可以在大多数路由器中打开特定端口或一系列端口的端口,也可以配置DMZ主机,以便所有进入该主机的主机.

2.您必须在那些设备上配置防火墙以允许该端口.

此方法的问题在于,每次重置路由器或更改新路由器时,都必须重新配置它.我不建议使用NAT端口映射或IGD,它们都会为恶意滥用提供漏洞",并且我认为大学不允许您在其路由器中使用这种软件.

另一种解决方案是将服务器用作网关,我的意思是使两个客户端都连接的服务器充当网关或路由器.当客户端A连接到服务器时,服务器会保留已连接客户端的列表并宣布这些客户端,而当客户端B要连接到客户端A时,服务器将进行从另一端到另一端的流量,手机,平板电脑, PC等.这样,您就不会遇到路由器(NAT)问题,因为两个客户端都可以连接到服务器.当然,这需要在服务器端进行大量工作,并且它必须是专用服务器.就像任何聊天应用程序(如Whatapps或Google Talk)一样,客户端与服务器对话,服务器将信息路由到适当的客户端.

Well, there are some implications here

1. You have to open ports in the router (NAT) so that it knows the IP of the PC/Device which is listening at that port. You can open ports in most of the routers either a specific port or a range of ports, also you may configure a DMZ host so that everything that comes in goes to that Host.

2. You have to configure the firewall at those Devices to allow this/these port/s.

The problem with this approach is that every time you reset the router or change a new router you have to re-configure it. I do not recommend NAT Port Mapping or IGD, they both create "holes" to malicious abuse, and I do not think the university allows you to use this kind of software in their routers.

Another solution is to use the Server as a gateway, I mean, make the server that both clients connect acts as a gateway or router. When client A connects to the server the server keeps a list of connected clients and announce these clients, when client B wants to connect to client A the server will do the traffic from one to another, it may be used by mobile phones, tablets, PC, etc. This way you don't have the router (NAT) problems since both clients make the connection to the server. Of course, this involves much work at server side and it must be a dedicated server. It's like any chat application like Whatapps or Google Talk, the clients talk to the server and the server routes the information to the appropriate client/s.

这篇关于在公共Internet上使用套接字的视频聊天应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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