1 / 22

MP2: P2P File Server

MP2: P2P File Server. Hoang Nguyen. 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

paige
Download Presentation

MP2: P2P File Server

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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 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. Basic network concepts revisited

  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. 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. 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. 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.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. Basic network programming revisited

  9. Basic network programming revisited • 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. 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. How to create a server socket? • Pseudo-code & examplefill out address informationsock_fd = create/set socket optionbind to the portlisten for incoming connectionswhile (forever || not crash) client_fd = accept a client socket create a process/thread to communicate with the client… // ready to send/recv

  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. 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. Sending/Receiving data • no_send = send(sock_fd, data, len, flag) • no_recv = recv(sock_fd, buf, max_len, flag) • Example

  15. Data serialization • Converting data objects into bits • Three ways: • Use readable string description: e.g. “text ‘this is a text’, int 1, float 1.1234” • 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. 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. In our MP…

  18. An example implementation of control planefor our MP Dispatcher setup peer-to-peer connections Handling a client request

  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. 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. Dispatcher setup connection cairo socket Bi-directional Socket on port 7000 Setup connection request cairo Bi-directional sanjose socket Setup connection request Socket on port 8000

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

More Related