HW1 discussion
Download
Report
Transcript HW1 discussion
Homework 1 Review
TA: Donghyun (David) Kim
Overall Architecture
Hybrid Peer-to-Peer System
Server
Client1
Client2
Server Description
Server responsibility
Server IP (IP-S) and Port Number (PORT-S) is known
Maintain the list of online-clients
Get IP-S in running time
Get PORT-S from input arguments
Prepare a data structure to maintain a list of client
information
Client ID (ID-C), Client IP (IP-C), and Client Port Number
(PORT-C)
Server Description – cont’
(IP-S, PORT-S)
Server
UDP
ID-C
IP-C
PORT-C
1
192.168.1.2
6000
2
192.168.1.5
6000
Server Description – cont’
Waiting for messages from clients via UDP
JOIN, ID-C, IP-C, PORT-C
LEAVE, ID
Assume no two messages arrives at the same time
When membership is changed, send the updated list to
the all of online-clients via UDP
In practice, only change can be sent
i.e. forward Join/leave message from a client to the other
clients
Server Description – cont’
(IP-S, PORT-S)
Server
ID-C
IP-C
PORT-C
1
192.168.1.2
6000
2
192.168.1.5
6000
UDP
JOIN/LEAVE
UPDATE on-line
client list of
Client Architecture
It is a peer (Client + Server)
Four user input arguments
Client ID (ID-C), Port number of the client (PORT-C)
ID-S, PORT-S
Learn its own IP (IP-C)
Two global variables
Thread1 and Thread2 should share one Boolean flag which
define their actions
A socket descriptor for the user to communicate with another
client
MODE: 1 or 2
SOCKET: -1 (disconnected) or other value
Assume no racing condition
Client Architecture – cont’
3 major threads (running at the same time)
Thread1
Thread2
Mode1: Handling user input and connecting to another client via TCP
Mode2: Handling user input when connected
Mode1: Listening a connection request from another via TCP
Mode2: Still, listening a connection request from another via TCP, but
reject all other requests.
Thread3
Send a JOIN message to the with (ID-C, IP-C, PORT-C)
Listening a membership update from the server via UDP
Client Architecture – cont’
Thread1
Mode1: Handling user input and connecting to another client via TCP
DISPLAY-LIST: display the up-to-date list of online-clients
After a session is established, the connection can be terminated by typing “BYE”
on any client
CONNECT ID-C: try establishing a connect to the client with ID-C
TERMINATE: terminate this client
Mode2: Handling user input when connected
Client
Thread1
Thread2
Thread3
Example
ID-C
(IP-S, PORT-S)
Server
UDP
IP-C
PORT-C
Example
ID-C
(IP-S, PORT-S)
Server
UDP
(IP-S, PORT-S
ID-C1, IP-C1, PORT-C1)
MODE: 1, SD: -1
Client1
JOIN (ID-C1, IP-C1, PORT-C1)
Thread1
Thread2
TCP
Thread3
UDP
IP-C
PORT-C
Example
(IP-S, PORT-S)
Server
ID-C
IP-C
PORT-C
ID-C1
IP-C1
PORT-C1
UDP
(IP-S, PORT-S
ID-C2, IP-C2, PORT-C2)
MODE: 1, SD: -1
MODE: 1, SD: -1
Client1
Client2
LIST{(ID-C1, IP-C1, PORT-C1)}
Thread1
Thread1
Thread2
TCP
TCP
Thread2
Thread3
UDP
UDP
Thread3
Example
(IP-S, PORT-S)
Server
ID-C
IP-C
PORT-C
ID-C1
IP-C1
PORT-C1
ID-C2
IP-C2
PORT-C2
UDP
(IP-S, PORT-S
ID-C2, IP-C2, PORT-C2)
MODE: 1, SD: -1
MODE: 1, SD: -1
Client1
Client2
JOIN (ID-C2, IP-C2, PORT-C2)
Thread1
Thread1
Thread2
TCP
TCP
Thread2
Thread3
UDP
UDP
Thread3
Example
(IP-S, PORT-S)
Server
ID-C
IP-C
PORT-C
ID-C1
IP-C1
PORT-C1
ID-C2
IP-C2
PORT-C2
UDP
LIST
{(ID-C1, IP-C1, PORT-C1),
(ID-C2, IP-C2, PORT-C2)}
MODE: 1, SD: -1
Client1
MODE: 1, SD: -1
Client2
Thread1
Thread1
Thread2
TCP
TCP
Thread2
Thread3
UDP
UDP
Thread3
Example
(IP-S, PORT-S)
Server
ID-C
IP-C
PORT-C
ID-C1
IP-C1
PORT-C1
ID-C2
IP-C2
PORT-C2
UDP
MODE: 1, SD: -1
MODE: 2, SD: 5
Client1
Client2
CONNECT REQ(ID-C2)
Thread1
TCP
Thread1
Thread2
TCP
TCP
Thread2
Thread3
UDP
UDP
Thread3
Example
(IP-S, PORT-S)
Server
ID-C
IP-C
PORT-C
ID-C1
IP-C1
PORT-C1
ID-C2
IP-C2
PORT-C2
UDP
MODE: 2, SD: 3
MODE: 2, SD: 5
Client1
Client2
Thread1
TCP
TCP
Thread1
Thread2
TCP
TCP
Thread2
Thread3
UDP
UDP
Thread3
Example
(IP-S, PORT-S)
Server
ID-C
IP-C
PORT-C
ID-C1
IP-C1
PORT-C1
ID-C2
IP-C2
PORT-C2
UDP
MODE: 2, SD: 3
MODE: 2, SD: 5
Client1
Client2
Thread1
TCP
Thread2
Thread3
BYE
TCP
Thread1
TCP
TCP
Thread2
UDP
UDP
Thread3
Example
(IP-S, PORT-S)
Server
ID-C
IP-C
PORT-C
ID-C1
IP-C1
PORT-C1
ID-C2
IP-C2
PORT-C2
UDP
MODE: 1, SD: -1
MODE: 1, SD: -1
Client1
Client2
Thread1
Thread1
Thread2
TCP
TCP
Thread2
Thread3
UDP
UDP
Thread3
Example
Server
(IP-S, PORT-S)
ID-C
IP-C
PORT-C
ID-C1
IP-C1
PORT-C1
ID-C2
IP-C2
PORT-C2
UDP
MODE: 1, SD: -1
Client1
MODE: 1, SD: -1
LEAVE (ID-C1)
Client2
Thread1
Thread1
Thread2
TCP
TCP
Thread2
Thread3
UDP
UDP
Thread3
Example
(IP-S, PORT-S)
ID-C
IP-C
PORT-C
ID-C2
IP-C2
PORT-C2
Server
UDP
LIST
{(ID-C2, IP-C2, PORT-C2)}
MODE: 1, SD: -1
Client2
Thread1
TCP
Thread2
UDP
Thread3