Table of Contents
- I made this project for college's final term assignment
- Subject: Unix Programming
- This project use
poll()
to handle multiple clients - Front-end & Back-end:
C
- Database:
mysql
- Server:
ngrok
- 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
Check "C & MySQL" and "MySQL" in Documents section for details
sudo apt install default-libmysqlclient-dev
create database [database name]
- Feel free to change
[database name]
- My was
socket_project
CREATE TABLE accounts(
id int NOT NULL PRIMARY KEY AUTO_INCREMENT COMMENT 'Primary Key',
username VARCHAR(255),
password VARCHAR(255)
) COMMENT '';
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 '';
In server_side/struct.h
change these following
#define HOST "localhost"
#define USER "root"
#define PASSWORD "20194616"
#define DATABASE "socket_programming"
bash setup.sh
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
bash client.sh [IP Address] [port]
- If you are going to specify
IP Address
orport
, 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
andport
- 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
orport
, 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
andport
Ngrok's website: link
sudo snap install 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 getIP Address
port
is 10955
- Use this website, input
- C & MySQL: website
- Bash scripting: youtube video & Google search
- Book: UNIX Network Programming(Volume1,3rd)
- Ngrok: TCP Tunnel
- MySQL: Install on Ubuntu