How to send data between two computers over the Internet

I struggled with this all day, I hope someone can help me with this.

My problem is quite simple: I want to transfer data (mostly simple commands) from one PC to another over the Internet.

I was able to achieve this using sockets in Java when both computers are connected to my home router. Then I connected both computers to the Internet using two different mobile phones and tried to transfer the data again. I used mobile phones, as this provides a direct route to the Internet, and if I use my router, I need to set up port forwarding, at least as I understand it.

I think the problem is how to configure the client socket. I used:

Socket kkSocket = new Socket(ipAddress, 3333); 

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

Also, are there more effective methods to solve my problem, such as using http, and if so, where can I find more information about this?

EDIT: Is it possible for a server program to run on a server on the Internet somewhere. Then my original server will be the client that sends the information to this server. This server will then pass this information to my original client and vice versa. Thus, the IP address of my computer does not matter, since I need to know the address of a server located somewhere on the Internet. Does this seem like a better solution? Where do I start to implement such a solution?

Thanks!

+6
java sockets
source share
4 answers

When you connected to the server running StackOverflow, did you enter the IP address? This is 64.34.119.12 if it runs through your memory.

You probably didn’t. You probably typed "stackoverflow.com". There is a huge, complex, smart and, in a sense , poorly implemented system called DNS , which translates reasonable and readable names into IP addresses.

One of the problems with DNS is that you need a “static IP address”, which is exactly what it looks like: an IP address that does not change, and that’s exactly what you don’t have.

So what can you do?

  • You can buy a static IP account from your Internet service provider (quite expensive)
  • You can use some proxy server on the Internet (a machine that has a static IP address and is ready to drop your packets back and forth). I don’t know a single service that will do this for you, you can write one and put it on Amazon Web Services or the Google App Engine, both of which will be free at your level of use, but they will be slow as each package trying to cross your living room will have to go through some data center in Virginia).
  • You can continue to do what you are doing by looking at the network configuration of your machine.
  • You can speed things up a bit (3) if your server program searches for its own IP address and prints it where you could see it, and enter it manually on the server.
  • You can use DynDNS as Sergey said (this is the “right” solution, since it is very general, it can be a little difficult to configure)
  • You can use multi-casting .

Multi-casting is an interesting solution, and it may work for you. The idea is that when your server starts, it announces on the network: "Here I am, I provide the X server, here is my IP address, talk to me." The problem is that multi-casting will not leave your living room. Obviously, if every multi-cast were distributed to every computer on the Internet, all of this would collapse, so your router would ignore and not route packets with multiple sheets. This may or may not be a deal breaker for you. EDIT After reading my question, I see that this is a robber for you. I would go with No. 5, but keep in mind that there may be problems with routing (address translations that do not allow the server to find out the address that other computers can find) or problems with fire (i.e. your ISP can prevent your server from receiving incoming packets, even if the address is correct).

+8
source share

Using a direct socket connection with port 3333 is usually more complicated because there are different network configurations.

firewalls will enjoy preventing a connection or killing it from time to time.

maintaining a two-way connection may not be standard. SIP is struggling with such problems.

For a simple application, I suggest you study comet technology where your clients can establish an http connection to a shared server. Then the server can hide the commands between them.

html5 will also result in a websocket protocol to the table.

+1
source share

I got the IP address by right-clicking on the connection, status, support.

Not sure about the "support" part, and now I'm not on a Windows computer, but I think the easiest and most reliable way to determine the IP address in Windows is to run "ipconfig" from the command line (Win + R, type "cmd" , then "ipconfig" in the window that opens). This, of course, must be done on the server side.

However, the problem is that, depending on the provider, your IP address may not be on the Internet, but on the provider's local network (called NAT). In this case, you need to use some kind of black magic called punching holes in TCP , which is very difficult and not guaranteed. You can find out if your address is local or not by looking at it. For IPv4, local addresses almost always look like 10.xxx or 172.16-31.xx or 192.168.xx I don’t know about IPv6.

You can also check your IP address by visiting one of the special sites, for example www.whatismyip.com . If the address that they tell you is different from the one you see by running "ipconfig" or looking at the connection properties, you are almost certainly behind NAT (or your ISP uses a transparent proxy, but this is rare).

If you are directly connected to the Internet (there are no local addresses and NATs), then you should also check if you have any firewall software, either configure it to allow connections to the port you are using, or make sure it is " it will ask "(and not" turn off silence ") or just turn it off completely (this can lead to the risk of your computer, especially if anti-virus software is missing or the system is not updated).

Also, is it possible to get a fixed name for my computer that I can use instead of entering an IP address, how does it change every time I connect to the Internet using my mobile phone?

Yes it is possible. There is a DynDNS feature, and there are DynDNS providers, such as DynDNS.com , where you can get a third-level domain name (for example, mycoolpc.dyndns.org) for free. You will need to install and configure the DynDNS client on your computer, which will tell the DynDNS server its new IP every time each of them is changed. I don’t know anything about specific clients, because I use one built-in in my home router.

+1
source share

You do not need to write network code for this, if it really does not float on your boat. Take a look at SCP. http://amath.colorado.edu/computing/software/man/scp.html There is a windows implementation where you can download putty (windows ssh client), and it is found on most Linux distributions. In addition, you can configure an FTP or SSH server on one or both machines.

“a fixed name for my computer that I can use instead of entering an IP address” would be a domain name that can be purchased online for a few dollars.

0
source share

All Articles