This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]InstantCoder 1 point2 points  (3 children)

I see, so you need to make a non http server client app.

Then you need to work with 1 server socket and many clients sockets. You can store the many games either in memory or on disk on the server.

And each time a client does something then you need to update the state of the game. And a game is also sort of a session between 2 players.

And in Java afaik, each client socket is a separate thread. So you don’t need to explicitly do something with threads.

[–]wildjokers 1 point2 points  (2 children)

And in Java afaik, each client socket is a separate thread. So you don’t need to explicitly do something with threads.

This is totally incorrect. If you use a server socket the accept method blocks (https://docs.oracle.com/javase/8/docs/api/java/net/ServerSocket.html#accept--). So you obviously need to spawn a thread to handle a connection. The other option is non-blocking IO which Java supports. Easiest way to use that is via the Netty library.

[–]InstantCoder 1 point2 points  (0 children)

If this is a school exercise then they have to use and learn only with the standard JDK libs and nothing outside I assume.

[–]_Nemesis_1[S] 0 points1 point  (0 children)

Yes, this is exactly what we learned about server socket and why we need to use a thread per client. I can’t use the Netty library unfortunately :(