CSC 4900 Computer Networks: P2P and Sockets

Similar documents
CMSC 332 Computer Networks P2P and Sockets

Chapter 2: Application layer

Application Layer: P2P File Distribution

CC451 Computer Networks

Last Lecture SMTP. SUNY at Buffalo; CSE 489/589 Modern Networking Concepts; Fall 2010; Instructor: Hung Q. Ngo 1

CS 3516: Advanced Computer Networks

Computer Networking Introduction

Application-Layer Protocols Peer-to-Peer Systems, Media Streaming & Content Delivery Networks

Lecture 8: Application Layer P2P Applications and DHTs

CS 3516: Computer Networks

CS 43: Computer Networks BitTorrent & Content Distribution. Kevin Webb Swarthmore College September 28, 2017

CSC 4900 Computer Networks: End-to-End Design

Section 2: Application layer

JAVA Network API. 2 - Connection-Oriented vs. Connectionless Communication

Chapter 2: outline. 2.6 P2P applications 2.7 socket programming with UDP and TCP

CSC 4900 Computer Networks: Transport Layer

CSC 401 Data and Computer Communications Networks

Lecture 05: Application Layer (Part 02) FTP, Peer-to-Peer, . Dr. Anis Koubaa

CMPE 150/L : Introduction to Computer Networks. Chen Qian Computer Engineering UCSC Baskin Engineering Lecture 6

Peer-to-Peer Applications Reading: 9.4

Chapter 2 Application Layer

ELEC / COMP 177 Fall Some slides from Kurose and Ross, Computer Networking, 5 th Edition

Chapter 2 Application Layer

CMSC 322 Computer Networks Applications and End-To- End

P2P Applications. Reti di Elaboratori Corso di Laurea in Informatica Università degli Studi di Roma La Sapienza Canale A-L Prof.ssa Chiara Petrioli

OBJECT ORIENTED PROGRAMMING

Transport Layer. The transport layer is responsible for the delivery of a message from one process to another. RSManiaol

internet technologies and standards

CSCI 466 Midterm Networks Fall 2013

Internet Protocol Stack! Principles of Network Applications! Some Network Apps" (and Their Protocols)! Application-Layer Protocols! Our goals:!

Interprocess Communication

Client/Server Computing & Socket Programming

Peer to Peer Networks

Chapter 7 Transport Layer. 7.0 Introduction 7.1 Transport Layer Protocols 7.2 TCP and UDP 7.3 Summary

Client/Server Computing & Socket Programming

Distributed Systems Recitation 2. Tamim Jabban

Computer Communication Networks Socket Programming

JAVA SOCKET PROGRAMMING

C18: Network Fundamentals and Reliable Sockets

Java Network Programming

CS 4390 Computer Networks. Transport Services and Protocols

Transport Layer. Gursharan Singh Tatla. Upendra Sharma. 1

CS 43: Computer Networks. 14: DHTs and CDNs October 3, 2018

NT1210 Introduction to Networking. Unit 10

Foundations of Telematics

Application Layer. Pure P2P architecture. Client-server architecture. Processes communicating. Hybrid of client-server and P2P. Creating a network app

Outlines. Networking in Java. Internet hardware structure. Networking Diagram. IP Address. Networking in Java. Networking basics

CSEN 503 Introduction to Communication Networks. Mervat AbuElkheir Hana Medhat Ayman Dayf. ** Slides are attributed to J. F.

Different Layers Lecture 21

CSC 401 Data and Computer Communications Networks

CSCD 330 Network Programming

Advanced Java Programming. Networking

Introduction to Socket Programming

3.2 COMMUNICATION AND INTERNET TECHNOLOGIES

CSCD 330 Network Programming Spring 2018

CS118 Discussion Week 2. Taqi

CSE 461 Module 10. Introduction to the Transport Layer

P2P Applications. Reti di Elaboratori Corso di Laurea in Informatica Università degli Studi di Roma La Sapienza

Internet Technology. 06. Exam 1 Review Paul Krzyzanowski. Rutgers University. Spring 2016

6.1 Internet Transport Layer Architecture 6.2 UDP (User Datagram Protocol) 6.3 TCP (Transmission Control Protocol) 6. Transport Layer 6-1

PLEASE READ CAREFULLY BEFORE YOU START

CS 3516: Advanced Computer Networks

Goal and A sample Network App

CSC 4900 Computer Networks:

Internet Technology 3/2/2016

Introduction to the Application Layer. Computer Networks Term B14

Chapter 3 Transport Layer

CompSci 356: Computer Network Architectures Lecture 21: Overlay Networks Chap 9.4. Xiaowei Yang

Networking and Security

Transport protocols Introduction

OSI Transport Layer. objectives

Lecture 11. Transport Layer (cont d) Transport Layer 1

ELEC / COMP 177 Fall Some slides from Kurose and Ross, Computer Networking, 5 th Edition

Distributed Systems Recitation 2. Tamim Jabban

IEMS 5780 / IERG 4080 Building and Deploying Scalable Machine Learning Services

Application Layer. Pure P2P architecture. Client-server architecture. Processes communicating. Hybrid of client-server and P2P. Creating a network app

OSI Transport Layer. Network Fundamentals Chapter 4. Version Cisco Systems, Inc. All rights reserved. Cisco Public 1

Transport Layer. <protocol, local-addr,local-port,foreign-addr,foreign-port> ϒ Client uses ephemeral ports /10 Joseph Cordina 2005

Chapter 2: outline. 2.1 principles of network applications. 2.6 P2P applications 2.7 socket programming with UDP and TCP

FTP. Mail. File Transfer Protocol (FTP) FTP commands, responses. Electronic Mail. TDTS06: Computer Networks

Chapter II: Application Layer

Communication in Distributed Systems: Sockets Programming. Operating Systems

Socket Programming. Dr. -Ing. Abdalkarim Awad. Informatik 7 Rechnernetze und Kommunikationssysteme

Transport Layer. Chapter 3: Transport Layer

CSC 4900 Computer Networks: Network Layer

Joseph Faber Wonderful Talking Machine (1845)

Chapter 2 Application Layer

UDP, TCP, IP multicast

Chapter 2. Application Layer. Chapter 2: Application Layer. Application layer - Overview. Some network apps. Creating a network appication

Lecture 2 - Application Layer. Lecture 1 Review. Application Layer. Principles of network applications. Notes. Notes. Notes. Notes

Outline of Topics. UDP Socket Java Programming. Multicast in Java. Real-time protocol (RTP) XMPP and Jingle protocols. Java I/O and New IO (NIO)

( A ) 1. WAP is a (A) protocol (B) hardware (C) software (D) network architecture

MIDTERM EXAMINATION #2 OPERATING SYSTEM CONCEPTS U N I V E R S I T Y O F W I N D S O R S C H O O L O F C O M P U T E R S C I E N C E

Computer Communication Networks Midterm Review

CN1047 INTRODUCTION TO COMPUTER NETWORKING CHAPTER 6 OSI MODEL TRANSPORT LAYER

Content Overlays (continued) Nick Feamster CS 7260 March 26, 2007

CMPE 150/L : Introduction to Computer Networks. Chen Qian Computer Engineering UCSC Baskin Engineering Lecture 4

CSCE 463/612 Networks and Distributed Processing Spring 2018

Operating Systems. 16. Networking. Paul Krzyzanowski. Rutgers University. Spring /6/ Paul Krzyzanowski

CSCD 330 Network Programming Spring 2018

Transcription:

CSC 4900 Computer Networks: P2P and Sockets Professor Henry Carter Fall 2017

Recap SMTP is the language that mail servers use to exchange messages. SMTP is push-based... why? You can run SMTP from a telnet window. Anything interesting here? 2

Chapter 2: Application Layer 2.1 Principles of network applications 2.2 Web and HTTP 2.3 Electronic Mail 2.4 DNS 2.5 P2P Applications 3

Pure P2P Architecture no always-on server arbitrary end systems directly communicate peers are intermittently connected and change IP addresses 4

File Distribution: Server-Client vs P2P Question: How much time does it take to distribute a file from one server to N peers? 5

File Distribution Time: Server-Client server transmission: must sequentially send (upload) N file copies: time to send one copy: F/us time to send N copies: NF/us client: each client must download file copy dmin = min client rate min client download time: F/dmin increases linearly in N (for large N) 6

File Distribution Time: P2P server transmission: must upload at least one copy: time to send one copy: F/us client: each client must download file copy min client download time: F/dmin clients: NF bits must be downloaded (aggregate) fastest possible upload rate: us + Σui increases linearly in N (for large N) same here! dp2p = max { F/us, F/dmin, NF/(us + Σui) } 7

Server-Client vs P2P: Example Client upload rate = u, F/u = 1 hour, us = 10u, dmin us 8

File Distribution: Bit Torrent Files divided into 256 Kb chunks Peers in torrent send/receive file chunks tracker: tracks peers participating in torrent torrent: group of peers exchanging chunks of a file 9

BitTorrent (continued) Peer joining torrent......has no chunks, but will accumulate them over time...registers with tracker to get list of peers, connects to subset of peers ( neighbors ) While downloading, peer uploads chunks to other peers. Churn: Peers may come and go. Once peer has entire file, it may (selfishly) leave or (altruistically) remain 10

BitTorrent (even more) Requesting Chunks at any given time, different peers have different subsets of file chunks periodically, a peer (Alice) asks each neighbor for list of chunks that they have. Alice sends requests for her missing chunks rarest first Sending Chunks Alice sends chunks to four neighbors currently sending her chunks at the highest rate re-evaluate top 4 every 10 secs every 30 secs: randomly select another peer, starts sending chunks newly chosen peer may join top 4 optimistically unchoke 11

BitTorrent: Tit-for-Tat 1. Alice optimistically unchokes Bob 2. Alice becomes one of Bob s top-four providers; Bob reciprocates 3. Bob becomes one of Alice s top-four providers With higher upload rate, can find better trading partners & get file faster! 12

P2P: Finding Information - Centralized Index original Napster design 1. When peer connects, it informs central server: IP address content 2. Alice queries for Hey Jude 3. Alice requests file from Bob 13

P2P: Problems with Centralized Directory Single point of failure Performance bottleneck Copyright infringement: target of lawsuit is file transfer is decentralized, but locating content is highly centralized obvious 14

P2P: Finding Information - Query Flooding Query message sent over existing TCP File transfer: HTTP connections peers forward Query message QueryHit sent over reverse path Scalability: limited scope flooding 15

Distributed Hash Tables DHT: a distributed P2P database database has (key, value) pairs; examples: key: ss number; value: human name key: movie title; value: IP address Distribute the (key, value) pairs over the (millions of peers) a peer queries DHT with key DHT returns values that match the key peers can also insert (key, value) pairs 16

Chapter 2: Summary Most importantly: We learned about protocols Communications architectures Client/Server P2P Hybrid Message Formats: headers vs. data Stateless vs Stateful Reliable vs Unreliable transfer Complexity at the network edge 17

Socket Programming Goal: learn how to build client/server application that communicate using sockets Socket API Explicitly created, used & released by apps client/server paradigm two types of transport service via socket API: unreliable datagram (UDP) socket a host-local, application-created, OS-controlled interface (a door ) into which an application process can both send and receive messages to/from another application process reliable, byte stream-oriented (TCP) 18

Socket-Programming Using TCP Goal: learn how to build client/server applications that communicate using sockets Socket: a door between application process and endend-transport protocol (UDP or TCP) 19

Just Like the Bank Tube You do not need to be aware of all of the operations that occur in the tube, but you can potentially impact transport. Selecting a solid capsule ensures reliable delivery of contents. A less solid capsule might send your spare change flying... 20

Socket Basics Creating a new socket Socket socket(string host, int port) host: A domain ( www.csc.villanova.edu ) or IP ( 153.104.202.74 ) port: The port to contact on the receiving domain For UDP: DatagramSocket socket() Address and port specified at send Closing a socket socketname.close(); Always use a try-catch in case of exceptions! 21

Specifying Addresses API uses the class InetAddress Each object stores the canonical domain name and IP address of a host Provides both IPv4 and IPv6 addresses Does NOT specify a port number! Can be automatically created for TCP sockets Recall that we only specified a String for the host 22

An Example Steps Store the IP address Store the port number (for later) Allocate the InetAddress variable Use the static method to create an InetAddress object String servip = 10.0.0.1 ; Int servport = 25; InetAddress servaddr; servaddr = InetAddress.getByName(servIP); 23

Socket Programming with TCP Client must contact server. Server process must be running. Server must have created a ServerSocket (door) the welcomes client s contact Client contacts server by: creating client TCP socket specifying IP address, port number of server process When client creates socket: client TCP establishes connection to server TCP When contacted by client, server TCP creates new socket for server process to communicate with client. Allows server to talk with multiple clients Source port numbers used to distinguish clients 24

TCP Basics In TCP, you must first create a connection (automatic at client) Socket sock = new Socket( 10.0.0.1, 900); Then, you can send and receive using Java InputStream and OutputStream OutputStream out = sock.getoutputstream(); out.write(byte[] data, int offset, int length); InputStream in = sock.getinputstream(); int bytesread = in.read(byte[] buffer, int offset, int length); 25

A Word About Boundaries TCP provides flow control Why is flow control important? This means the data provided to write() might be broken into parts The same goes for read() Moral: do not assume correspondence between write() and read() Commonly place read() inside a while loop (until returned bytes is -1 (stream closed)) Also, sender and receiver may have different buffer sizes 26

Java Stream Composition Java has several IO classes to handle byte streams more easily Buffered[Input/Output]Stream Data[Input/Ouptut]Stream Cipher[Input/Output]Stream These classes add buffering, delimiting, and encoding automatically Make sure you are using the appropriate matching Input Stream on the opposite end of the connection! 27

Socket programming with UDP UDP: no connection between client and server no handshaking sender explicitly attaches IP address and port of destination to each packet server must extract IP address, port of sender from received packet UDP: transmitted data may be received out of order, or lost application viewpoint UDP provides unreliable transfer of groups of bytes ( datagrams ) between client and server 28

TCP Server TCP servers perform the following steps Create a new socket with a port (ServerSocket(int port)) The system will automatically listen for connections once bound to a port Repeatedly accept and process connections accept(), do stuff, close() 29

Listening Once the socket is bound to a port, the server will listen for new connections. We can specify an upper bound on the number of incoming connections in the constructor Example: ServerSocket ss = new ServerSocket(int port, int queuelimit); 30

Processing Connections New client connections are accepted with accept() Socket accept() The returned Socket object is then used analogously to the client socket for sending and receiving with the connected client The call blocks until a new connection occurs Example: Socket clientsock = serversock.accept(); 31

Simultaneous Connections There is more than one way to handle multiple simultaneous connections multiple processes (ProcessBuilder) multiple threads (Thread) What about listening on multiple ports? multiplexing (Java.nio) Take a look at Java.nio See TCP/IP Sockets in Java (or your favorite reference) for more information 32

Constructing Messages Until now, we have only discussed sending character strings How do we send more complex data structures? We convert data structures to and from byte arrays serialization, deserialization marshalling, unmarshalling deflating, inflating Remember, we must be cognizant of Endianess Network format (big endian) Java format (??? endian) 33

Encoding data There are multiple ways of encoding data Convert numbers to strings representing each digit send the bytes directly When does the receiver stop receiving? We can use a delimiter We can establish predefined data formats What if data is an arbitrary length? Data framing: use a header of a predefined size. The header has fixed sized fields and specifies size of data 34

Recap P2P Sharing Allows the bandwidth of distributing files to be spread more evenly between participants instead of at a single server bottleneck Socket Programming Connecting and transferring bytes between processes 35

Next Time... Textbook Chapter 3.1-3.3 Remember, you need to read it BEFORE you come to class! Homework Project #1 is due in a week! 36