• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Newbie to internet connecting 2 computers through java swing app questions?

 
mike lim
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I'm trying to learn how to connect 2 computers from different locations through internet (not on a local network). I did some research and wrote some code but I get errors when running the 2 programs (1 client app and 1 server app). Here's the code..

server:


and the client:



any help? Am I doing something wrong? I run the server application first the click the button to listen then run the client app from another computer.. Thanks in advance..
 
Norm Radder
Rancher
Posts: 3795
35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

 I get errors


Please copy the full text of the error message and paste it here. It has important info about the error.

You need the correct IP address.  An address starting with 192.168 is for a local net.
Then you'll need to tell the router to let you connect.
 
mike lim
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On the client side the error is just that it says it timed out. I see is my IP address wrong..? How can I get an address from a remote computer on the internet..? I just copied the IP from running ipconfig on the server computer..
 
Norm Radder
Rancher
Posts: 3795
35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

How can I get an address


One way is to ask google what your IP address is. For example try this: what is my ip
There is a website that will tell you.  Perhaps your router knows.
 
mike lim
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just did that, and I tried to ping the server IP with the global IP address I got from google in the command prompt of the client computer, it says timed out.. Is it because of the firewall? Should I use something like Hamachi to make it easier to connect 2 remote computers?
 
Norm Radder
Rancher
Posts: 3795
35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes there cou;d be a firewall or other configuration that needs to be done with the server's router for you to access your code.  I have never done it myself so i can not advise anymore.
 
mike lim
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I read that there's some port forwarding involved or something. It seems like a security risk to do that.. I'm just wondering how other programs can just connect to other computers such as zoom video calling or messaging apps like facebook messenger/viber/skype without doing any configurations involved.. why does Java have to configure your router/firewall..
 
Adrian Grabowski
Rancher
Posts: 167
7
Mac OS X IntelliJ IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will need to find out your public IP address and then set up port forwarding on your router.
 
mike lim
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Adrian Grabowski wrote:You will need to find out your public IP address and then set up port forwarding on your router.



isn't it risky to setup port forwarding?
 
Adrian Grabowski
Rancher
Posts: 167
7
Mac OS X IntelliJ IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

mike lim wrote:why does Java have to configure your router/firewall..



It's nothing to do with Java. If you host your server app on some VPN than your client apps can connect it with no problems just by providing the IP address (and port), no port forwarding needed.
 
mike lim
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I just tried out Hamachi, and it works, it connects. But then I get the error java.net.SocketException: Connection reset.. it doesn't print out the string that was sent, it just connects..

Hamachi seems to work.. are there any other VPNs out there I can use..
 
Norm Radder
Rancher
Posts: 3795
35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

how other programs can just connect to other computers such as zoom video calling or messaging apps like facebook messenger/viber/skype without doing any configurations involved.


Your compute is a client, not a server for those applications.
 
mike lim
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

mike lim wrote:Yes, I just tried out Hamachi, and it works, it connects. But then I get the error java.net.SocketException: Connection reset.. it doesn't print out the string that was sent, it just connects..

Hamachi seems to work.. are there any other VPNs out there I can use..



Oh I got it to work sending a message sorry, I forgot to initialize my BufferedOutputStream..
 
mike lim
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Norm Radder wrote:

how other programs can just connect to other computers such as zoom video calling or messaging apps like facebook messenger/viber/skype without doing any configurations involved.


Your compute is a client, not a server for those applications.



Got it.. thanks..
 
Ron McLeod
Sheriff
Posts: 3122
459
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

mike lim wrote:How can I get an address from a remote computer on the internet..?


You could ask the IP Chicken.
 
Whose rules are you playing by? This tiny ad doesn't respect those rules:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic