I am trying to connect 2 computer in my home using DatagramSockets (or even Sockets) in java. What exactly should I do? Which IP Address should I use to connect them?
-
1192.168.x.y is typically used for home networking. But this is really not a question for this community. – GhostCat Sep 30 '18 at 11:55
2 Answers
If your machine is using DHCP
then it's not upto you to decide which ip address you will use. Your machine will be assigned some dynamic ip address. To see that use ifconfig
on Linux box and ipconfig
on win machine. Once you have their IP address you can use these to connect your machine. Chances are high that your machine has dynamic ip's.

- 524
- 5
- 9
Assuming you're a windows user:
to get your LAN IP address open a command prompt and type ipconfig
.
A bunch of stuff will show up, you are looking for the line that says
IPv4 address.....: 192.168.#.#
It should be noted however, that this is a so "dynamic" ip address, that can be changed whenever you disconnect and reconnect from your router.
I recommend that you either make your ip static (look this up on google, there are lots of tutorials) or use your computers hostname instead. To obtain your hostname you simply type hostname
in the commandprompt.
in your code you can get your ip address by doing this in your client code:
String ip = Inet4Address.getByName("<your servers hostname>").getHostAddress();
I hope this helps, although questions like these belong on Super User, as they really don't have much to do with coding.

- 36
- 6