[英]Sockets - Connect two computers on the same network with no port forwarding?
I am very confused.我很迷茫。 I cannot find a specific answer to my conundrum.
我找不到我的难题的具体答案。 I figured this applies to all languages, but I'm writing my application in Java specifically.
我认为这适用于所有语言,但我专门用 Java 编写我的应用程序。
So, I am simply trying to connect two separate computers, which are running on the SAME network.所以,我只是想连接两台在同一网络上运行的独立计算机。
Computer 'A' is the server, and Computer 'B' is the client.计算机“A”是服务器,计算机“B”是客户端。
When the Client connects, I just want to display a message on the server.当客户端连接时,我只想在服务器上显示一条消息。
My question: Is it possible to connect two PC's (one being the server, the other being the client), on the same network, without any kind of port forwarding, or other internet settings (with the exception of some firewall settings)?我的问题:是否可以在同一网络上连接两台 PC(一台是服务器,另一台是客户端),而无需任何类型的端口转发或其他 Internet 设置(某些防火墙设置除外)? Also, what IP do you have to use to connect the two PC's?
另外,您必须使用什么IP来连接两台PC?
Thank you very much!非常感谢你!
You don't need port forwarding.您不需要端口转发。 All you need to do on the server is something like
您需要在服务器上做的就是
ServerSocket ss = new ServerSocket(KNOWN_PORT);
while(running) {
executor.submit(new SocketHandler(ss.accept()));
On the client side在客户端
Socket s = new Socket(KNOWN_HOST, KNOWN_PORT);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.