How to get started online in Java?

I would like to program a game that can be played by several players sitting in front of another computer who are connected through a network, and I want to use Java for this. In this regard, I have a few questions. I will be glad if you answer at least one question.

  • I can imagine two different situations. In the first, I create a local area network between computers. In the second case, I use the Internet as a medium for communication between computers. So, my first question is: if the two above cases require different approaches (from a software point of view).

  • The second question is how computers can identify each other. For example, two computers are connected to the Internet, and, theoretically, they can see each other. But how does the first computer know how to refer to the second? Maybe computers should know each other's IP addresses? But what if the IP addresses are dynamic? Every time the IP address changes, will the connection be lost?

  • If I use a local area network, is it possible for each computer to see everything on the network?

  • Say my computer knows the address of another computer. What can he do with it? Can I send a file to this computer? How does the second computer know that something has been sent to it? How does the second computer know what to do with the file? Should I run on a second computer a program that constantly checks that something has arrived, and if something has arrived (file), the program must know what to do with it.

+3
source share
3 answers

I agree with the above comment β€œBears will eat you”, that you can start by reading / research, such as:

book See the reviews here.

+2
source
  • , ServerSocket , , . , , IP- , . ( java- Socket)

  • , , . , , .

  • , , "".

  • java, (Socket, ServerSocket...). , .

+1
  • The two cases are identical in terms of software. However, you need to consider things like proxies and firewalls. A socket connection may work on a local network, but a failure over the Internet.

  • The easiest way to solve this is to have a server that will help you in your discovery. All users are registered on the server, and then can be easily detected by other users. Each system needs to know the IP address of the server.

  • Yes. Take the firewalls again.

  • A central scenario can also help in this scenario.

+1
source

Source: https://habr.com/ru/post/1733539/


All Articles