Warning

If it is not explicitly told in following recipe, setting up services are described for Ubuntu 24.04 server, but applications are described for Xubuntu 24.04 workstation. If you use different Ubuntu version or Linux distribution, settings as well as content, names and places of configuration files may be different!
Got it.

Multi user TTT

Prev
JPA
Next
Chat client

Main steps

Review theory

  1. If necessary, review presentations:

    1. Threads
    2. Multiuser network game

Implement multiuser TTT server

  1. Investigate jtm.extra07 package
  2. The server reads the TCP port from the port key in src/main/resources/application.properties
  3. Implement class TttNetMultiuser:
  4. open a ServerSocket on the configured port,
  5. accept two client connections (Player 1 — ×, Player 2 — ○),
  6. start the game with new TttCli(input1, output1, input2, output2, size),
  7. run each pair of clients in a separate thread, so several games can run in parallel,
  8. close the client sockets when the game ends and log errors.
  9. The optional first command-line argument is the board size, e.g.:

    java -cp target/classes jtm.extra07.TttNetMultiuser 2
  10. Check server with nc (or telnet)

    1. Because you need two players, open two terminals and connect one client in each:
    nc 127.0.1.1 7700
  11. To check if server is listening on necessary port, run:

    ss -ntlp | grep 7700

    or:

    netstat -antp | grep 7700
  12. If necessary, server can be killed with:

    kill -9 pid
    where pid is process id from the previous command

Prev
JPA
Next
Chat client

 
 

Created by Valdis Vītoliņš on 2026-03-19 12:38
Last modified by Valdis Vītoliņš on 2026-11-25 12:59
XWiki Powered
Creative Commons Attribution 3.0 Unported License