Skip to content

laurenb-asl/SocketGames

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

154 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SocketGames

Sometimes one simply wants to play text games across a TCP socket. For those times, this project (requires Java8 or higher).

The project consists of two packages:

  • org.asl.socketserver which contains the server framework
  • org.asl.socketserver.games which contains sample games

Game classes written for this project should abide by the following four guidelines:

  • provide a default constructor (to permit no-arg instantiation inside a thread)
  • implement the Servable interface (thread life is bounded by Servable.serve())
  • extend AbstractGame (to enable setting/retrieving best score data)
  • annotate the class with a @MenuInfo annotation (provides content for menus)

Compiled class files meeting these criteria and stored in the org/asl/socketserver/games folder will be identified automatically by the server and made available for play.

A running server may be accessed from a remote shell or terminal using netcat, telnet, etc. For example:

  • netcat localhost 9090 // connect to a server running on the same machine using port 9090
  • netcat 10.30.5.46 4187 // connect to a remote server at address 10.30.4.46 over port 4187
  • // the port number specified by the client must match the port number used when starting the server

Documentation

Compiled Javadoc for the project is available here: https://apcsjava.github.io/SocketGames/

Notes for compiling and running inside an IDE (Eclipse, say)

The main application class is GameServer. It requires two command line arguments -- the port number and the maximum number of connections to accept. In Eclipse, go to "Run Configurations ..." and under the Arguments tab, enter "9090 5", for example, to run the server on port 9090 and accept a maximum of 5 simultaneous connections.

Notes for compiling and running outside of an IDE (command line)

The server must be compiled before it can be run. If you are compiling from the root folder of the distribution, this will take a form such as:

  • javac org/asl/socketserver/GameServer.java.
    This will compile not only the server but all related and dependent classes in the org.asl.socketserver package.

To compile all classes in the games folder:

  • javac org/asl/socketserver/games/*.java

Launch the compiled server as follows:

  • java org/asl/socketserver/GameServer 9090 5 // launches the server on port 9090 and accepts up to 5 simultaneous connections
  • java org/asl/socketserver/GameServer // launches the server on an arbitrary, open port (check System.out for details) with a capacity of 10 users.

About

Sometimes one simply wants to play a text game across a TCP socket. For those times, this project.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Java 100.0%