Group Chatting with P2P File Transfer
Overview
- Term project in Embedded OS course (Undergraduate)
- Chatting program that have with P2P file transfer function
- If you want to know more information about its source code, visit my Github
Idea
- Design Server-Client architecture with socket programming (Developed with C language)
- Using TCP/IP protocol (Transfer layer in OSI 7 layers) in communication
- Based in Ubuntu server, so need to know Linux command and vim code editor
Description
- This project is required port assignment to build up server and client
- In this project, it needs 1 server and 2 clients (Server ↔ Client#1, Client#2)
- To implement this program, it should be followed step by step process
- Server-Client Model
- Group Chatting
- P2P File Transfer
Server-Client Model
- Properties
- A user accesses the server
- Each user has to log-in the server with ID/PW
- Background for implementing group chatting
-
Model structure
-
Key Idea
-
How much know about
fork()
method -
fork()
- Create child process from parent process (Copy-Paste form)
-
-
Result
Group Chatting
- Properties
- 1 server, 2 more clients architecture based on Server-Client Model
- In this part, several fork() calls are required
-
Model structure
-
Key Idea
-
There are many other methods to implement Group Chatting, Client#1 ↔ Server ↔ Client#2
-
For me, I used
pipe()
method. Refer more about pipe() -
pipe()
- Connection between two processes, useful for communication between related processes
- Parent and child sharing a pipe
-
My Group Chatting architecture using
pipe()
method
-
-
Result
-
Server
-
Client 1
-
Client 2
-
P2P File Transfer
-
Properties
- When log in, make clients are sending their P2P IP/Port#
- If a special msg(e.g., “[FILE]”) is received, a P2P file transfer process is starting
- P2P file transfer process - when Client#1 require file transfer to Client#2
- Client#1 receive file lists from Client#2
- Client#1 choose file, and send file’s number to Client#2
- Client#1 receive file successfully
- P2P Server-Client is newly generated with P2P IP/Port#. (additional fork() calls are required)
- In P2P network, there are no master-slave relationship
- So original communication(Server) need to be disconnected and direct communication between client1,2 should be established
-
Model Structure
-
Key Idea
-
There are many other methods to implement file transfer
-
For me, I used
dirent.h
header file to show file lists of Client -
dirent.h
-
Header file that can handle directory files
-
Structure
-
struct dirent { long d_ino; //l-노드 번호 off_t d_off; //offset unsigned short d_reclen; //파일 이름 길이 char d_name[NAME_MAX+1]; //파일 이름 }
-
-
Usage function (In this project)
opendir()
readdir()
closedir()
-
-
About file transfer between Client#1 and Client#2, I devised some
trick(?)solution- When Client#2 send file lists, send its content additionally to Client#1
- So if Client#1 select one file, then it can be reasonable to create requested file in Client#1 itself
-
-
Result
-
Server - User1(client1) request [FILE]
-
Client#1 - Change P2P network and Select ‘a-2.txt’ file that is third in file list
-
Client#2 - Change P2P network in IP/Port#1 of client#1 and Send file list
-
Development Environment
- Putty - Ubuntu Server (OS : Linux)
- WinSCP
- Vim - Code Editor (Used C language)
Reference
- Socket Programming
- Linux/Unix Programming Environment
- Vi Editor
Leave a comment