See this Java tutorial for a lucid introduction to TCP sockets with demonstration programs, upon which much of our code is based. Note that both the client and server have code for a client Socket whereas only the server includes code for a ServerSocket.
Three of these demonstrations merely echo the same string that was passed to the server. Simple echoes are useful for testing network connections. The demonstrations start with the simplest (which allows only one echo per client) then gradually gain in complexity. We use the third echo client-server application as a base for developing into an application to help with solving crosswords. You could use clients to send scores of your game to a file under the control of a server and to retrieve the current highest score.
There are plenty of opportunities for errors in networking, and we have included some error checking to remind you of this. As usual, we check less than we should to keep the code relatively short and easy to follow.
You might encounter problems due to port blocking by one or more firewalls and need to add new rules to allow access to your chosen port. We advise you to put the server on a Raspberry Pi, which does allow access by default. Use the commands ifconfig and ipconfig to find the IP address of a PC and a Pi, respectively. All our demonstrations run with the client(s) and the server on a single PC or Pi. Enter in the client the IP 127.0.0.1 for the local machine address of the server.
We input from the keyboard an array of SByte (signed byte) to convert to a String because an array of Byte does not work in the way it did before signed numbers were introduced to Oxygene for Java in July 2013.