Git Product home page Git Product logo

tic-tac-toe-game-using-network-socket-apis's Introduction

Game: Tic-tac-toe using Network Socket APIs

Table of Contents
  1. About
  2. Technologies
  3. How to setup MySQL
  4. How to run Client and Server
  5. How to use Ngrok
  6. Documents

About

  • I made this project for college's final term assignment
  • Subject: Unix Programming

Technologies

  • This project use poll() to handle multiple clients
  • Front-end & Back-end: C
  • Database: mysql
  • Server: ngrok

Prerequisite

  • OS: Ubuntu 22.04.1 LTS x86_64
  • gcc (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0
  • mysql: 8.0.31-0ubuntu0.22.04.1 for Linux on x86_64
  • ngrok: 3.1.0

How to setup MySQL

To install MySQL on Ubuntu

Check "C & MySQL" and "MySQL" in Documents section for details

To enable MySQL API in C

sudo apt install default-libmysqlclient-dev

Create database

create database [database name]
  • Feel free to change [database name]
  • My was socket_project

Create accounts table

CREATE TABLE accounts(  
    id int NOT NULL PRIMARY KEY AUTO_INCREMENT COMMENT 'Primary Key',
    username VARCHAR(255),
    password VARCHAR(255)
) COMMENT '';

Create games table

CREATE TABLE games(  
    id int NOT NULL PRIMARY KEY AUTO_INCREMENT COMMENT 'Primary Key',
    date VARCHAR(255),
    first_player VARCHAR(255),
    second_player VARCHAR(255),
    board_size INT,
    moves VARCHAR(255)
) COMMENT '';

Changing Host, User, Password

In server_side/struct.h change these following

#define HOST "localhost"
#define USER "root"
#define PASSWORD "20194616"
#define DATABASE "socket_programming"

How to run Client and Server

To clean up all .o files

bash setup.sh

To run server

bash server.sh [port]
  • You can specify any port you want
  • Default port is 8888
  • You don't have to run this if the server is already running on other machine

To run client without Docker

bash client.sh [IP Address] [port]
  • If you are going to specify IP Address or port, you need to specify both
  • Defaul IP Address and port are: 127.0.0.1 8888
  • To connect to server, you need to specify both IP Address and port

To run client using Docker

  • Build image client_side-client
cd client_side
docker compose build
  • Run container in bash mode
docker container run -it socket-client bash
  • Run client
./client [IP Address] [port]
  • If you are going to specify IP Address or port, you need to specify both
  • Defaul IP Address and port are: 127.0.0.1 8888
  • To connect to server, you need to specify both IP Address and port

How to use ngrok

Ngrok's website: link

To install on Ubuntu

sudo snap install ngrok

To host ngrok

ngrok tcp [port]
  • port must be the same as server's local port
  • Example result: tcp://0.tcp.ap.ngrok.io:10955
    • Use this website, input 0.tcp.ap.ngrok.io to get IP Address
    • port is 10955

Documents

tic-tac-toe-game-using-network-socket-apis's People

Contributors

manhlamabc123 avatar manhlamabc avatar

Watchers

 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.