Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 MP2: P2P File Server Hoang Nguyen. 2 Outline Basic network concepts revisited –Client/Server, Peer-to-peer –IP address, TCP/UDP Basic network programming.

Similar presentations


Presentation on theme: "1 MP2: P2P File Server Hoang Nguyen. 2 Outline Basic network concepts revisited –Client/Server, Peer-to-peer –IP address, TCP/UDP Basic network programming."— Presentation transcript:

1 1 MP2: P2P File Server Hoang Nguyen

2 2 Outline Basic network concepts revisited –Client/Server, Peer-to-peer –IP address, TCP/UDP Basic network programming revisited –Server socket, Client Socket –Send/Receive data –Data Serialization: converting objects to bits Network Design: Control/Data plane –MP explanation –Implementation suggestions/hints

3 3 Basic network concepts revisited

4 4 Basic network concepts (1) Client/server –Servers = machines providing network services –Clients = machines connecting to servers and use network services –Example: FTP server/FTP client

5 5 Basic network concepts (2) A server provides a network service through a “port” –Has to “bind” to a particular port Clients requests for a specific service at a server via a pre-defined port E.g.: Port 21: FTP control, Port 20: FTP data Port: (0..65535) –0..1023: well-known ports, requiring admin right to bind –1024..49151: registered ports (for propriety apps) –The rest: dynamic/private ports

6 6 Basic network concepts (3) What is a Protocol? –A convention standard that controls or enables the connection, communication and data transfer between two parties. Example: –“Protocol” to apply to UIUC –“Admission protocol” In our MP, we will have to define our own “protocols” and use some existing network protocols

7 7 Basic network concepts (3) IP address: a tuple of four 8-bit integers –E.g.: 128.174.252.84 Host name: name representative of IP –E.g.: www.cs.uiuc.eduwww.cs.uiuc.edu TCP: Transmission Control Protocol –Reliable, ordered, heavy-weight, streaming (connection- oriented/stateful) –Suitable for any applications requiring reliability such as FTP UDP: User Datagram Protocol –Unreliable, not-ordered, light-weight, datagrams (connectionless/stateless) –Suitable for any protocols that can tolerate reasonable losses such as video/audio/real-time streaming

8 8 Basic network programming revisited

9 9 Highly recommended tutorial –Beej's Guide to Network Programming Using Internet Sockets http://beej.us/guide/bgnet/ Make sure you go through until Section 7 (esp. Section 6 and Section 7.4)

10 10 Network Socket A socket is a one end of a two-way communications link between two programs running on the network –In UNIX, socket is just a file descriptor on which send() and recv() can be used. As mentioned above, a socket can be –SOCK_STREAM: streaming, reliable, connection- oriented, ordered –SOCK_DGRAM: datagram, unreliable, connection- less, not-ordered

11 11 How to create a server socket? Pseudo-code & example fill out address information sock_fd = create/set socket option bind to the port listen for incoming connections while (forever || not crash) client_fd = accept a client socket create a process/thread to communicate with the client … // ready to send/recv

12 12 Comments sock_fd: Server socket keeps listening for incoming connections –If the accept() function is not invoked, no client connection can be accepted –If the number of pending connections exceeds the backlog, any incoming requests are refused. client_fd: socket to communicate with the client –Think of it like a file descriptor.

13 13 How to create a client socket? Pseudo-code & example fill out address information (hostname, port) sock_fd = connect to the server … // ready to send/recv

14 14 Sending/Receiving data no_send = send(sock_fd, data, len, flag) no_recv = recv(sock_fd, buf, max_len, flag) Example

15 15 Data serialization Converting data objects into bits Three ways: 1)Use readable string description: e.g. “text ‘this is a text’, int 1, float 1.1234” 2)Sending raw data, passing it send() (dangerous, un- portable) double d = 3490.15926535; send(s, &d, sizeof d, 0); 3) Encode the data into a portable binary form. The receiver encodes it. (see pack(), unpack() in the tutorial)

16 16 Control/Data Plane Control plane: a set of protocols/software to bootstrap/setup and control the communication Data plane: a set of protocols/software to transmit data E.g.: FTP has two ports for control channel (21) and data channel (20)

17 17 In our MP…

18 18 An example implementation of control plane for our MP 1)Dispatcher setup peer-to-peer connections 2)Handling a client request

19 19 Entities (1) A server has –a server socket listening on port 7000 for dispatcher setup connection request –a client socket to communicate with dispatcher obtained once accepting dispatcher setup connection request –an on-demand server socket listening on a on- demand port for the client to send/recv data

20 20 Entities (2) A dispatcher has –several client sockets for connections to each server –a server socket listening on port 8000 for clients to send/recv control messages A client has –A client socket to send/recv control messages to the dispatcher –A client socket to send/recv data to the server

21 21 Dispatcher setup connection Socket on port 7000 Setup connection request socket Socket on port 8000 socket Setup connection request Bi-directional cairo sanjose

22 22 Handling a client request socket Bi-directional Socket on port 8000 cairo sanjose 1. request 2. request 3. response 4. response


Download ppt "1 MP2: P2P File Server Hoang Nguyen. 2 Outline Basic network concepts revisited –Client/Server, Peer-to-peer –IP address, TCP/UDP Basic network programming."

Similar presentations


Ads by Google