简体   繁体   English

套接字 - 在没有端口转发的情况下连接同一网络上的两台计算机?

[英]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.

相关问题 有没有办法通过不同网络上的双向连接连接两台计算机(一个具有端口转发) - Is there a way to connect two computers with a two-way connection on different networks (one has port forwarding) 连接两个客户端而无需端口转发 - Connect two clients without port forwarding 使用Java DatagramSockets,我可以将两个不同的套接字连接到同一本地端口但在不同的本地地址吗? - With Java DatagramSockets, can I connect two different sockets to the same local port but on different local addresses? 连接两个客户端套接字 - Connect two client sockets 是否在没有端口转发的情况下将套接字连接到SeverSocket(0)? - Have socket connect to SeverSocket(0) without port forwarding? 我可以使用Java中的套接字连接两台计算机吗? - Can I connect 2-computers using sockets in java? 如何在两个单独的程序上将两个套接字绑定到同一端口? - How can I bind two sockets to the same port on two separate programs? Java NIO套接字,可以在任何可用的端口连接吗? - Java NIO sockets, connect at any available port? 连接两台计算机(通过无线网络的机器) - Connecting two computers(machines over a wireless network) 使用套接字远程连接两台非本地计算机 - Remotely connecting two non-local computers with sockets
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM