Giter Site home page Giter Site logo

connect-fout-client-server's Introduction

Connect Four

Connect Four is a network based game implemented using both TCP and UDP protocols to communicate. By default both the TCP and UDP implementations use Binary encoding to transmit the information from the client to the server. The original purpose of this project is based on the course work for parallel and distributed systems, which was a two-part project. Part one involved creating a TCP based client for the game of Nim. The second part involved converting the Nim client to UDP and implementing our own server. Using my knowledge I remade the Nim, based Client/Server to a Connect Four Client/Server game by changing the UI and converting the backend to support the new UI. Then I took it a step further and remade the project so that it would use only TCP.

The main points of this project are:

  • Java
  • Threading
  • MVC
  • Swing
  • Network Communication (TCP and UDP)

Client Server Implementation

The Server works by first parsing the input to get the host and port adress. The Server then infinitley loops so that multiple sessions may be started. Within the loop the main thread gets blocked by the serversockets accept method which blocks until a client connects. At which point the server checks if that client has previously connected to the server, and if it hasn't it creates a new instance of the viewproxy object which is responsible for recieving messages from the client and reporting them to the underlying boardmodel (Except for the "Join" message which is reported to the SessionManager). It then sets the SessionManager as the proxy's ViewListener. The SessionManager has one job, it calls the "Join" method which determines if there is an open session or not. If there isn't one, a new ConnectModel instance is created and the sessionmanger waits unitl another session is available. Once the second client connects the Sessionmanager links the second client to the same ConnectModel that the first client is attached two and the game can commence.

ViewListener Methods Binary Encoding Textual Encoding
placed(int id, int x, int y)
  • 'P' (1 byte)
  • id (integer, 1 byte)
  • x (integer, byte)
  • y (integer, 1 byte)
join(String name)
  • 'J' (UTF-8 1 byte)
  • name (UTF-8 String)
newgame() 'N' (1 byte)
quit() 'Q" (1 byte)
ModelListener Methods Binary Encoding Texual Encoding
id(int id)
  • 'I' (1 byte)
  • id (integer, 1 byte)
name(int id, String name)
  • 'N' (1 byte)
  • id (integer, 1 byte)
  • name (UTF-8 String)
score(int id, int score)
  • 'S' (1 byte)
  • id (integer, 1 byte)
  • score (integer 1 byte)
reset() 'H' (1 byte)
move(int id, int x, int y)
  • 'M' (1 byte)
  • id (integer, 1 byte)
  • x (integer, 1 byte)
  • y (integer, 1 byte)
turn(int id)
  • 'T' (1 byte)
  • id (integer, 1 byte)
win(int id)
  • 'W' (1 byte)
  • id (integer, 1 byte)
quit() 'Q' (1 byte)
Representation of how the Client and Server communicate:

Client/Server

Representation of SessionManager:

Session Manager

Game Images:

First Client Connects and must wait until another player joins.

Session Manager

Secound Client Connects and the "New Game" button is enabled and the first player now has the ability to make a move

Session Manager

Playthrough of the first game

Session Manager

A player wins and the player scores are updated as well as the third box reports the winner to both players.

Session Manager

A plater hits "New Game" and the board is reset.

Session Manager

Two new players connect to the server.

Session Manager

Two sets of games going on simultaneously, The top two are the original players the bottom two are the new players who are independent of the top two.

Session Manager

connect-fout-client-server's People

Contributors

michaelrinos avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.