简体   繁体   English

Java 代理背后的套接字编程

[英]Java Socket Programming behind proxy

I have written a TCP IP socket program which works fine.我写了一个 TCP IP 套接字程序,它工作正常。 But my socket program did not work if my server or client is behind proxy.但是如果我的服务器或客户端在代理后面,我的套接字程序就不起作用。 So how to overcome from this type of issue.那么如何克服这类问题。

Thanks Bapi谢谢巴皮

Well there's two issues to consider:那么有两个问题需要考虑:

  1. Behind a proxy;在代理后面; and
  2. Behind a firewall.在防火墙后面。

Firewall tends to be easier: you simply use port 80 (HTTP) or 443 (HTTPS).防火墙往往更容易:您只需使用端口 80 (HTTP) 或 443 (HTTPS)。 Proxy is harder because direct network communication tends to be disabled from normal PCs.代理更难,因为直接网络通信往往被普通 PC 禁用。

This is why you often find people using HTTP and/or SSL as their transport mediums because they bypass these kinds of security issues.这就是为什么你经常发现人们使用 HTTP 和/或 SSL 作为他们的传输媒介,因为他们绕过了这些类型的安全问题。 You can do push content (with long-lived connections aka Comet techniques) so there's typically no real technical reason not to.您可以推送内容(使用长期连接,也就是 Comet 技术),因此通常没有真正的技术理由不这样做。

But it's hard to say one way or the other if that's a good idea or not without knowing more about your application and any pertinent requirements.但是,如果不了解您的应用程序和任何相关要求的更多信息,就很难说这是否是一个好主意。

Proxies usually work at the application level, not at the transport level.代理通常在应用程序级别工作,而不是在传输级别。 Here is some information about Java and proxies.以下是有关 Java 和代理的一些信息

Depending on the proxy, there may be little that you can do.根据代理的不同,您可能无能为力。 If the Proxy is designed to block all traffic that it does not directly handle, then you have to either go through the proxy, somehow working with it, or you have to find a way to sneak through the proxy.如果代理旨在阻止它不直接处理的所有流量,那么您必须通过代理 go 以某种方式使用它,或者您必须找到一种方法潜入代理。

For example, many applications are built on top of HTTP precisely because it is commonly allowed through firewalls and is commonly proxy-friendly.例如,许多应用程序都构建在 HTTP 之上,正是因为它通常允许通过防火墙并且通常对代理友好。 Thus, it's a pretty safe way of communicating when you know that you'll be installing the application in environments where proxies may exist.因此,当您知道将在可能存在代理的环境中安装应用程序时,这是一种非常安全的通信方式。

In your case, it depends on what port(s) your application uses, on whether these ports are commonly handled by a proxy for any existing protocol, on whether or not you're using a standard (commonly known) protocol or have invented your own, and so on.在您的情况下,这取决于您的应用程序使用的端口,这些端口是否通常由任何现有协议的代理处理,取决于您是否使用标准(众所周知)协议或发明了您的自己的,等等。

Is this proxy a transparent proxy?这个代理是透明代理吗? (That is, do web browsers have to be configured to see it, or not?) The kind of proxy it is determines part of how your application needs to work with it. (也就是说,web 浏览器是否必须配置才能看到它?)代理类型决定了您的应用程序需要如何使用它。 Is the proxy controlled by your organization?代理是否由您的组织控制?

You say you are using port 5018. Just as an experiment, can you try using port 80?你说你用的是5018端口,作为一个实验,你可以试试用80端口吗? Just because you're using port 80 doesn't mean you have to use HTTP.仅仅因为您使用端口 80 并不意味着您必须使用 HTTP。 This is worth a try to see if it helps.这值得一试,看看是否有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM