Multiplayer game in Java. Connect client (player) to game that was created by other client

前端 未结 2 2087
时光说笑
时光说笑 2020-12-18 18:08

I am working on multiplayer game and I cant to find out how can I connect other clients to the created game. I mean that client A create a socket connection to the server an

2条回答
  •  长情又很酷
    2020-12-18 18:39

    Here is one way to handle it. When a player wants to create a game, his copy of the application should open a ServerSocket on a known port - a port number that the application knows - and maybe display to the player the IP address that the socket was opened on.

    Then when another player wants to join a game, she should enter that same IP address and her copy of the application should connect using a regular client Socket, the IP address entered, and the known port that the application knows.

    Check the Socket and ServerSocket javadoc for details.

提交回复
热议问题