简体   繁体   English

Java TCP客户端服务器通过LAN使用端口转发,但不使用hamachi

[英]Java TCP Client Server working over LAN with port Forwarding but not with hamachi

I have a basic Java Client Server TCP Programm which is able to connect over LAN and also when i use my public ip with port forwarding. 我有一个基本的Java客户端服务器TCP程序,该程序可以通过LAN进行连接,也可以在将公共IP与端口转发一起使用时进行连接。

What bothers me, is that it does not work when i try to use the same programm inside of a hamachi VPN network. 令我困扰的是,当我尝试在hamachi VPN网络中使用相同的程序时,它不起作用。 I want to get it to work there as well, as many people try to avoid port forwarding but use hamachi as it seems easier for them. 我希望它也能在那里工作,因为许多人都试图避免端口转发,但使用hamachi似乎对他们来说更容易。

Server Code ss = new ServerSocket(4444); 服务器代码ss = new ServerSocket(4444); Client c = ss.accept(); 客户端c = ss.accept();

Client Code Socket client = new Socket(, 4444); 客户端代码套接字client = new Socket(,4444); printWriter = new PrintWriter( new OutputStreamWriter( client.getOutputStream())); printWriter = new PrintWriter(new OutputStreamWriter(client.getOutputStream()));

I googled and could not find any information about this problem, as usual people ask how to avoid port forwarding and are told to use hamachi for example or learn how to forward their ports. 我搜索了谷歌,但没有找到有关此问题的任何信息,因为通常人们会问如何避免端口转发,并被告知使用例如hamachi或学习如何转发其端口。

Thanks in advance! 提前致谢!

Could hamachi actually be blocking a port? hamachi真的可以堵住港口吗? I like to use ncat and nmap to test for these things. 我喜欢使用ncatnmap来测试这些东西。

"ncat -l portNumber" will start a server listening on portNumber “ ncat -l portNumber”将启动服务器侦听portNumber

"nmap -Pn -p1234 someHost" will see if port 1234 is open on someHost (without doing a ping to determine if the host is up first) “ nmap -Pn -p1234 someHost”将查看是否在someHost上打开了端口1234(无需执行ping以确定主机是否先启动)。

Setup the above with your server and client, try it for your port 4444 and try it with some ports that nobody blocks like 80 or 443. If it works for those normal ports, but not for 4444, then something (hamachi?) is blocking that port. 使用服务器和客户端设置以上内容,尝试将其用于端口4444,然后将其与没有人阻止的某些端口一起尝试,例如80或443。如果它适用于那些普通端口,但不适用于4444,则表示某些东西(hamachi?)被阻止了该端口。

该错误是程序的另一部分确实关闭了某些流,并且在java中,关闭一个封装的流会关闭其下的所有内容。

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

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