如何通过Internet在两台计算机之间发送数据 [英] How do I send data between two computers over the internet

查看:132
本文介绍了如何通过Internet在两台计算机之间发送数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一整天都在努力解决这个问题,我希望有人可以帮我解决这个问题。

I have been struggling with this for the entire day now, I hope somebody can help me with this.

我的问题很简单:我希望传输数据(主要是简单的命令)通过互联网从一台PC到另一台PC。

My problem is fairly simple: I wish to transfer data (mostly simple commands) from one PC to another over the internet.

当两台计算机连接到我的家用路由器时,我已经能够使用Java中的套接字来实现这一点。然后,我使用两个不同的移动电话将两台计算机连接到互联网,并尝试再次传输数据。我使用移动电话,因为这提供了到互联网的直接路由,如果我使用我的路由器,我必须设置端口转发,至少,这是我理解它。

I have been able to achieve this using sockets in Java when both computers are connected to my home router. I then connected both computers to the internet using two different mobile phones and attempted to transmit the data again. I used the mobile phones as this provides a direct route to the internet and if I use my router I have to set up port forwarding, at least, that is how I understand it.

我认为问题在于我设置客户端套接字的方法。我用过:

I think the problem lies in the method that I set up the client socket. I used:

Socket kkSocket = new Socket(ipAddress, 3333);

其中ipAddress是运行服务器的计算机的IP地址。我通过右键单击连接,状态,支持来获取IP地址。这是正确使用的IP地址还是在哪里可以获取服务器的地址?此外,是否可以为我的计算机获取一个固定的名称,而不是输入IP地址,因为每次我使用手机连接到互联网时这都会改变?

where ipAddress is the IP address of the computer running the server. I got the IP address by right-clicking on the connection, status, support. Is that the correct IP address to use or where can I obtain the address of the server? Also, is it possible to get a fixed name for my computer that I can use instead of entering the IP address, as this changes every time I connect to the internet using my mobile phone?

或者,是否有更好的方法来解决我的问题,例如使用http,如果是,我在哪里可以找到更多相关信息?

Alternatively, are there better methods to solving my problem such as using http, and if so, where can I find more information about this?

编辑:
是否可以让服务器程序在互联网上的某个服务器上运行。我的原始服务器将是一个向该服务器发送信息的客户端。然后,此服务器将此信息传递给我的原始客户端,反之亦然。这样,我的计算机的IP地址无关紧要,因为我只需要知道在网络上某处托管的服务器的地址。这似乎是一个更好的解决方案吗?我从哪里开始实施这样的解决方案?

Would it be possible to have the server program running on a server on the internet somewhere. My original server would then be a client that send information to this server. This server would then pass this information to my original client and vice versa. That way, the IP address of my computer won't matter, as I only need to know the address of the server hosted somewhere on the web. Does this seem like a better solution? Where do I begin implementing such a solution?

谢谢!

推荐答案

当您连接到服务的服务器时StackOverflow,你输入了IP地址吗?它是64.34.119.12,如果那慢跑你的记忆。

When you connected to the server that serves StackOverflow, did you type in the IP address? It's 64.34.119.12, if that jogs your memory.

你可能没有。你可能输入了stackoverflow.com。有一个巨大的,复杂的,聪明的,并且在某些方面,实施不当的系统称为 DNS 知识和人类可读的IP地址名称。

You probably didn't. You probably typed "stackoverflow.com". There's a huge, complex, clever, and in some ways, poorly implemented system called DNS that translates sensible and human-readable names into IP addresses.

DNS的一个问题是,你需要一个静态IP,这听起来就是这样的: IP地址不会改变,这正是你没有的。

One problem with DNS, though, is you need a "static IP", which is exactly what it sounds like: an IP address that doesn't change, which is exactly what you don't have.

那么,你能做什么?


  1. 您可以从ISP购买静态IP帐户(相当昂贵)

  2. 您可以在互联网上使用一些代理服务器(一台机器, 拥有静态IP,并且愿意来回反弹您的数据包 - 我不知道有任何服务可以为您做这些事情;您可以编写一个并将其放在Amazon Web Services上或Google App Engine这将是你的使用水平免费,但他们会很慢,因为每个试图穿过你的客厅的包都必须通过弗吉尼亚州的一些数据中心。)

  3. 你可以继续做你正在做的事情,查看你的机器的网络配置。

  4. 你可以通过让你的服务器程序查找它自己来加快(3) IP地址并将其打印到您可以看到的位置并手动将其输入服务器。

  5. 您可以使用DynDNS,正如谢尔盖所​​说(这是正确的解决方案,在它很一般,设置可能有点复杂)

  6. 你可以使用多播

  1. You can buy a static IP account from your ISP (pretty expensive)
  2. You can use some proxy out in the Internet (a machine that does have a static IP and is willing to bounce your packets back and forth -- I'm not aware of any service that does this for you; you could write one and put it up on Amazon Web Services or Google App Engine, both of which would be free at your level of usage, but they'd be slow, since every packet trying to cross your living room would have have to go via some data-center in Virginia).
  3. You can keep doing what you're doing, looking in the net-configuration of your machine.
  4. You could speed (3) up a little by having your server program look up its own IP address and print it out where you could see it and type it into the server by hand.
  5. You can use DynDNS, as Sergey mentioned (this is the "right" solution, in that it's very general, it just might be a little complicated to set up)
  6. You can use multi-casting.

多播是一个有趣的解决方案,它可能适合您。这个想法是,当你的服务器启动时,它向网络宣布:我在这里,我正在提供X服务器,这是我的IP地址,请跟我说说。问题是,多播不会离开你的起居室。显然,如果每个多播都传播到互联网上的每台计算机上,整个事情就会崩溃,所以你的路由器会忽略而不是路由多播数据包。这可能是也可能不是你的交易破坏者。 编辑重新阅读您的问题,我认为 是您的交易破坏者。我会选择#5,但要注意可能存在路由问题(防止服务器知道其他计算机可以找到的地址的地址转换)或防火墙问题(也就是说,您的ISP可能会阻止您的服务器即使地址正确,也可以接收传入的数据包。)

Multi-casting is an interesting solution, and it may work for you. The idea is, when your server starts up, it announces to the net, "Here I am, I'm providing X server, here's my IP address, talk to me." The problem is, a multi-cast won't leave your living room. Obviously, if every multi-cast were spread to every computer on the Internet, the whole thing would collapse, so your router will ignore, and not route, multi-cast packets. That may or may not be a deal-breaker for you. EDIT Re-reading your question, I see it is a deal-breaker for you. I'd go with #5, but be aware there may be routing issues (address translations that prevent a server from knowing the address that other computers can find it at) or fire-wall issues (that is, your ISP may prevent your server from receiving incoming packets even if the address is correct).

这篇关于如何通过Internet在两台计算机之间发送数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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