https://github.com/romulodm/go-chess
A multiplayer chess game made with React and Gorilla WebSocket.
https://github.com/romulodm/go-chess
chess chess-game go gorilla-websocket react websocket
Last synced: 4 months ago
JSON representation
A multiplayer chess game made with React and Gorilla WebSocket.
- Host: GitHub
- URL: https://github.com/romulodm/go-chess
- Owner: romulodm
- Created: 2023-12-07T00:42:16.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2025-02-07T03:43:04.000Z (over 1 year ago)
- Last Synced: 2025-03-28T19:38:55.274Z (about 1 year ago)
- Topics: chess, chess-game, go, gorilla-websocket, react, websocket
- Language: JavaScript
- Homepage: https://go-chess-ws.vercel.app
- Size: 393 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# :mag_right: Overview
This project was created for a university subject called "Programming Languages", with the objective of creating an application in a programming language that we are not very used to using, the language chosen was Go and the idea was to use WebSockets to perform real-time communication between two users in a chess match.
Figure 1: Home page
# :seedling: Technologies
**Front-end:**
- `React`
- `Chess.js`
- `Chessboardjsx`
- `Material UI`
- `Tailwind CSS`
**Back-end:**
- `Go`
- `net/http`
- `Gorilla WebSocket`
# :newspaper: Description
We have implemented rooms that can have a maximum of two users connected, that is, they are private rooms for a chess game. We use the Gorilla WebSocket framework to create Rooms that have an identification ID, used to enter a room.
Room
```go
type Room struct {
ID string `json:"id"`
clients map[*Client]bool
register chan *Client
unregister chan *Client
broadcast chan *Message
}
```
Client
```go
type Client struct {
Name string
conn *websocket.Conn
send chan []byte
room *Room
}
```
In other words, we have two endpoints that upgrade the connection, the first is to create a room and the other is to enter an existing room. In these two endpoints we receive a front-end ID.
Server config
```go
func serverConfig() http.Server {
r := mux.NewRouter()
r.HandleFunc("/create-room", func(w http.ResponseWriter, r *http.Request) {
server.CreateRoom(w, r)
})
r.HandleFunc("/join-room", func(w http.ResponseWriter, r *http.Request) {
server.JoinRoom(w, r)
})
return http.Server{
Addr: "127.0.0.1:8000",
Handler: r,
ReadTimeout: 15 * time.Second,
ReadHeaderTimeout: 15 * time.Second,
}
}
```
Component that makes the requests
Figure 2: Lobby component
Figure 3: Game page
# :electric_plug: WebSocket
HTTP is a stateless communication protocol based on request and response transactions. In this model, the client sends a request to the server, which responds with the requested data. Each transaction is independent, and the connection is terminated after each interaction.
Figure 4: Differences between HTTP and WebSocket
In contrast, WebSocket establishes a persistent connection between the client and server, enabling continuous bidirectional communication. This full-duplex protocol allows both parties to send and receive data simultaneously, facilitating efficient real-time message transmission without the need to initiate new transactions for each interaction, as is the case with HTTP.
# :busts_in_silhouette: Contributors