使用TCP / IP在两台不同的计算机之间进行通信 [英] Communicating between two different computers with TCP/IP

查看:1855
本文介绍了使用TCP / IP在两台不同的计算机之间进行通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在研究如何使用套接字来让两个java程序进行通信。

I've been studying how to use sockets to make two java programs communicate.

现在,在我经历的每个例子中,它们总是被放置客户端程序所在的同一台计算机上的服务器端程序,当然IP集是127.0.0.1,或者只是localhost。

Now, on each example I've gone through, they've always placed the "server side program" on the same computer on which the "client side program" was, and of course the IP set was either 127.0.0.1 , or simply "localhost".

现在,我的问题是:
如果一个计算机在一台计算机上,另一个程序在另一个程序上,我该如何通信? / strong>

Now, my question is: how do I get to communicate the two programs if one is on a computer, and one on another?

我尝试将IP设置为我的计算机连接到互联网时的IP(我只是通过Google搜索我的IP是什么找到的) ,但这样似乎不起作用。
任何人都可以更好地解释我如何使它工作吗?

I've tried to set the IP as the one my computer has when connected to internet (the one I found simply by googling "what's my IP"), but that way it doesn't seems to work. Can anyone explain me better how I can make it work?

推荐答案

计算机需要在同一台计算机上网络或其IP地址将需要互联网访问。如果您在Windows中,可以通过打开cmd窗口(按Windows键+ R然后键入cmd)并运行ipconfig来查找本地IP地址。在Linux上(也许它也适用于Mac)你可以在终端上运行ifconfig。如果您的计算机位于同一局域网中,则应该能够使用这些命令指示的IP地址。

The computers will need to be on the same network or their IP address will need to be accessible to the internet. If you are in windows, you can find the local IP address by opening a cmd window (press windows key + R then type cmd) and running ipconfig. On linux (maybe it works on Mac as well) you can run ifconfig in a terminal. If your computers are on the same local area network you should be able to use the IP addresses indicated by those commands.

如果它们不在同一局域网中,计算机之间的路由器可能具有阻止连接的防火墙策略。

If they are not on the same local area network, a router in between the computers may have a firewall policy which is blocking the connection.

这篇关于使用TCP / IP在两台不同的计算机之间进行通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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