1 / 48

EEC-484/584 Computer Networks

This lecture covers the topics of email, FTP, and socket programming in computer networks. It includes an introduction to SMTP, MIME, and FTP protocols, as well as sample commands and responses.

lwm
Télécharger la présentation

EEC-484/584 Computer Networks

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. EEC-484/584Computer Networks Lecture 6 Wenbing Zhao wenbing@ieee.org (Part of the slides are based on Drs. Kurose & Ross’s slides for their Computer Networking book, and on materials supplied by Dr. Louise Moser at UCSB and Prentice-Hall)

  2. Outline • Mock quiz • Email, FTP • Socket programming • Physical layer – transmission theory • Ethereal Labs: can be downloaded at • http://www-net.cs.umass.edu/ethereal-labs/ EEC-484/584: Computer Networks

  3. Three major components: user agents mail servers simple mail transfer protocol: SMTP User Agent “mail reader” composing, editing, reading mail messages outgoing, incoming messages stored on server user agent user agent user agent user agent user agent user agent SMTP SMTP SMTP mail server mail server mail server outgoing message queue user mailbox Electronic Mail EEC-484/584: Computer Networks

  4. Mail Servers mailbox contains incoming messages for user message queue of outgoing (to be sent) mail messages SMTP protocol between mail servers to send email messages client: sending mail server “server”: receiving mail server user agent user agent user agent user agent user agent user agent SMTP SMTP SMTP mail server mail server mail server Electronic Mail: Mail Servers EEC-484/584: Computer Networks

  5. Uses TCP to reliably transfer email message from client to server, port 25 Direct transfer: sending server to receiving server The receiving server may be either the ultimate destination or an intermediate Three phases of transfer Handshaking (greeting) Transfer of messages Closure SMTP [RFC 2821] EEC-484/584: Computer Networks

  6. SMTP [RFC 2821] • Command/response interaction • Commands: ASCII text • Response: status code and phrase • SMTP requires message (header & body) to be in 7-bit ASCII • SMTP server uses CRLF.CRLF to determine end of message EEC-484/584: Computer Networks

  7. 1) Alice uses UA to compose message and “to” bob@someschool.edu 2) Alice’s UA sends message to her mail server; message placed in message queue 3) Client side of SMTP opens TCP connection with Bob’s mail server 4) SMTP client sends Alice’s message over the TCP connection 5) Bob’s mail server places the message in Bob’s mailbox 6) Bob invokes his user agent to read message user agent user agent mail server mail server Alice Sends Message to Bob 1 2 6 3 4 5 EEC-484/584: Computer Networks

  8. Sample SMTP Interaction S: 220 hamburger.edu C: HELO crepes.fr S: 250 Hello crepes.fr, pleased to meet you C: MAIL FROM: <alice@crepes.fr> S: 250 alice@crepes.fr... Sender ok C: RCPT TO: <bob@hamburger.edu> S: 250 bob@hamburger.edu ... Recipient ok C: DATA S: 354 Enter mail, end with "." on a line by itself C: Do you like ketchup? C: How about pickles? C: . S: 250 Message accepted for delivery C: QUIT S: 221 hamburger.edu closing connection EEC-484/584: Computer Networks

  9. Comparison of SMTP and HTTP • HTTP: pull • SMTP: push • Both have ASCII command/response interaction, status codes • HTTP: each object encapsulated in its own response message • SMTP: multiple objects sent in multipart message EEC-484/584: Computer Networks

  10. SMTP: protocol for exchanging email msgs RFC 822: standard for text message format: Header lines, e.g., To: From: Subject: differentfrom SMTP commands! Body: the “message”, ASCII characters only Mail Message Format header blank line body EEC-484/584: Computer Networks

  11. MIME: Multipurpose Internet Mail Extensions, RFC 2045, 2056 Additional lines in msg header declare MIME content type Purpose: Define encoding rules for non-ASCII messages From: alice@crepes.fr To: bob@hamburger.edu Subject: Picture of yummy crepe. MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Type: image/jpeg base64 encoded data ..... ......................... ......base64 encoded data Message Format: Multimedia Extensions MIME version method used to encode data multimedia data type, subtype, parameter declaration encoded data EEC-484/584: Computer Networks

  12. Transfer file to/from remote host, server on port 21 Client/server model Client: side initiates transfer (either to/from remote) Server: remote host FTP: RFC 959 FTP user interface FTP client FTP server local file system FTP: File Transfer Protocol file transfer user at host remote file system EEC-484/584: Computer Networks

  13. TCP control connection port 21 TCP data connection port 20 FTP client FTP server FTP: Separate Control, Data Connections • Control connection: “out of band” • FTP server maintains “state”: current directory, earlier authentication Active FTP is shown EEC-484/584: Computer Networks

  14. Sample commands: sent as ASCII text over control channel USER username PASS password LISTreturn list of file in current directory RETR filenameretrieves (gets) file STOR filenamestores (puts) file onto remote host FTP Commands and Responses EEC-484/584: Computer Networks

  15. FTP Commands and Responses Sample return codes • status code and phrase (as in HTTP) • 331 Username OK, password required • 125 data connection already open; transfer starting • 425 Can’t open data connection • 452 Error writing file EEC-484/584: Computer Networks

  16. a host-local, application-created, OS-controlledinterface (a “door”) into which application process can both send and receive messages to/from another application process socket 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 • Reliable, byte stream-oriented EEC-484/584: Computer Networks

  17. process process TCP with buffers, variables TCP with buffers, variables socket socket Socket Programming with TCP Socket: a door between application process and end-to-end transport protocol (UCP or TCP) TCP service: reliable transfer of bytesfrom one process to another controlled by application developer controlled by application developer controlled by operating system controlled by operating system internet host or server host or server EEC-484/584: Computer Networks

  18. Client must contact server Server process must first be running Server must have created socket (door) that welcomes client’s contact Client contacts server by: Creating client-local TCP socket Specifying IP address, port number of server process When client creates socket: client TCP establishes connection to server TCP (Java only) For C/C++, you need to call connect() explicitly Socket Programming with TCP EEC-484/584: Computer Networks

  19. TCP provides reliable, in-order transfer of bytes (“pipe”) between client and server application viewpoint Socket Programming with 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 EEC-484/584: Computer Networks

  20. create socket, connect to hostid, port=x create socket, port=x, for incoming request: clientSocket = Socket() welcomeSocket = ServerSocket() TCP connection setup wait for incoming connection request connectionSocket = welcomeSocket.accept() send request using clientSocket read request from connectionSocket write reply to connectionSocket read reply from clientSocket close connectionSocket close clientSocket Client/Server Socket Interaction: TCP Server (running on hostid) Client EEC-484/584: Computer Networks

  21. A stream is a sequence of characters that flow into or out of a process An input stream is attached to some input source for the process, e.g., keyboard or socket An output stream is attached to an output source, e.g., monitor or socket inFromUser inFromServer outToServer Stream Jargon (Java) Keyboard Monitor Input Stream Client process Process Input Stream Output Stream client TCP socket clientSocket TCP Socket to network from network EEC-484/584: Computer Networks

  22. Example client-server app: 1) Client reads line from standard input (inFromUser stream) , sends to server via socket (outToServer stream) 2) Server reads line from socket 3) Server converts line to uppercase, sends back to client 4) Client reads, prints modified line from socket (inFromServer stream) Socket Programming with TCP EEC-484/584: Computer Networks

  23. Example: Java client (TCP) import java.io.*; import java.net.*; class TCPClient { public static void main(String argv[]) throws Exception { String sentence; String modifiedSentence; BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in)); Socket clientSocket = new Socket("hostname", 6789); DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream()); Create input stream Create client socket, connect to server Create output stream attached to socket EEC-484/584: Computer Networks

  24. Example: Java Client (TCP) Create input stream attached to socket BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); sentence = inFromUser.readLine(); outToServer.writeBytes(sentence + '\n'); modifiedSentence = inFromServer.readLine(); System.out.println("FROM SERVER: " + modifiedSentence); clientSocket.close(); } } Send line to server Read line from server EEC-484/584: Computer Networks

  25. Example: Java Server (TCP) import java.io.*; import java.net.*; class TCPServer { public static void main(String argv[]) throws Exception { String clientSentence; String capitalizedSentence; ServerSocket welcomeSocket = new ServerSocket(6789); while(true) { Socket connectionSocket = welcomeSocket.accept(); BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream())); Create welcoming socket at port 6789 Wait, on welcoming socket for contact by client Create input stream, attached to socket EEC-484/584: Computer Networks

  26. Example: Java Server (TCP) DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream()); clientSentence = inFromClient.readLine(); capitalizedSentence = clientSentence.toUpperCase() + '\n'; outToClient.writeBytes(capitalizedSentence); } } } Create output stream, attached to socket Read in line from socket Write out line to socket End of while loop, loop back and wait for another client connection EEC-484/584: Computer Networks

  27. 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 provides unreliable transfer of groups of bytes (“datagrams”) between client and server application viewpoint Socket Programming with UDP UDP: transmitted data may be received out of order, or lost EEC-484/584: Computer Networks

  28. Client create socket, port=x, for incoming request: serverSocket = DatagramSocket() create socket, clientSocket = DatagramSocket() Create, address (hostid, port=x, send datagram request using clientSocket read request from serverSocket write reply to serverSocket specifying client host address, port number read reply from clientSocket close clientSocket Client/Server Socket Interaction: UDP Server (running on hostid) EEC-484/584: Computer Networks

  29. inFromUser receivePacket sendPacket Example: Java Client (UDP) Keyboard Monitor Input Stream Client process Input:receives packet (recall that TCP received “byte stream”) Output:sends packet (recall that TCP sent “byte stream”) Process UDP Packet UDP Packet client TCP socket Client UDP Socket to network from network EEC-484/584: Computer Networks

  30. Example: Java Client (UDP) import java.io.*; import java.net.*; class UDPClient { public static void main(String args[]) throws Exception { BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in)); DatagramSocket clientSocket = new DatagramSocket(); InetAddress IPAddress = InetAddress.getByName("hostname"); byte[] sendData = new byte[1024]; byte[] receiveData = new byte[1024]; String sentence = inFromUser.readLine(); sendData = sentence.getBytes(); Create input stream Create client socket Translate hostname to IP address using DNS EEC-484/584: Computer Networks

  31. Example: Java Client (UDP) Create datagram with data-to-send, length, IP addr, port DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, 9876); clientSocket.send(sendPacket); DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length); clientSocket.receive(receivePacket); String modifiedSentence = new String(receivePacket.getData()); System.out.println("FROM SERVER:" + modifiedSentence); clientSocket.close(); } } Send datagram to server Read datagram from server EEC-484/584: Computer Networks

  32. Example: Java Server (UDP) import java.io.*; import java.net.*; class UDPServer { public static void main(String args[]) throws Exception { DatagramSocket serverSocket = new DatagramSocket(9876); byte[] receiveData = new byte[1024]; byte[] sendData = new byte[1024]; while(true) { DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length); serverSocket.receive(receivePacket); Create datagram socket at port 9876 Create space for received datagram Receive datagram EEC-484/584: Computer Networks

  33. Example: Java Server (UDP) String sentence = new String(receivePacket.getData()); InetAddress IPAddress = receivePacket.getAddress(); int port = receivePacket.getPort(); String capitalizedSentence = sentence.toUpperCase(); sendData = capitalizedSentence.getBytes(); DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, port); serverSocket.send(sendPacket); } } } Get IP addr port #, of sender Create datagram to send to client Write out datagram to socket End of while loop, loop back and wait for another datagram EEC-484/584: Computer Networks

  34. Theoretical Basis for Data Communication • Fourier analysis • Bandwidth-limited signals • Maximum data rate of channel EEC-484/584: Computer Networks

  35. Fourier Analysis • Info is transmitted by varying voltage or current • Let f(t) be value of voltage or current at time t, any well-behaved periodic functiong(t) with period T can be represented as Fourier series n-th harmonics EEC-484/584: Computer Networks

  36. Fourier Analysis • Fundamental frequency f=1/T • an and bn are sine and cosine amplitudes of nth harmonics (terms) • The amplitudes and constant are given by EEC-484/584: Computer Networks

  37. Fourier Analysis • The more harmonics we include in transmission, the more accurate the signal is • Bottom line: we must at least include 1 harmonic Sending a byte ‘b’ EEC-484/584: Computer Networks

  38. Fourier Analysis • The more harmonics we include in transmission, the easier to reconstruct the signal EEC-484/584: Computer Networks

  39. Bandwidth-Limited Signals • Problem with physical medium • Signal attenuates during propagation • Signals with different frequencies might attenuate different => distortion of the signal shape • Cutoff frequency: The Fourier amplitudes are transmitted undiminished from 0 up to some frequency fc • fc is measured in cycles/sec or Hertz (Hz) • fc is usually determined as the frequency at which half the power gets through EEC-484/584: Computer Networks

  40. Bandwidth-Limited Signals • Bandwidth: The range of frequencies transmitted without being strongly attenuated, i.e., 0 - fc • The bandwidth is a physical property of the transmission medium and usually depends the construction, thickness, and length of the medium EEC-484/584: Computer Networks

  41. Bandwidth-Limited Signals • Artificial limitation on bandwidth: A filter is introduced into the circuit to limit the amount of bandwidth available to each customer • For example, a telephone wire may have a bandwidth of 1 MHz for short distances, but telephone companies add a filter restricting each customer to about 3100 Hz EEC-484/584: Computer Networks

  42. Bandwidth and Data Rate • Data rate: how many bits can you send per second? • Higher data rate, shorter T, or higher fundamental frequency f • You need to allow at least a couple of harmonics to go through to reconstruct the signal • Higher data rate => requires higher bandwidth EEC-484/584: Computer Networks

  43. Bandwidth and Data Rate • Example: • Voice line cut off frequency ~ 3000Hz • Data rate is b bits/sec • During each period, send 8 bits => f = b/8 Hz • If b = 9600 bps • Number of highest harmonic ~ 3000/(b/8) = 24000/b= 2.5 => poor reception EEC-484/584: Computer Networks

  44. Nyquist Theorem • For noiseless channels • Number of sampling needed to reconstruct an arbitrary signal transmitted through a low-pass filter of bandwidth H => 2H • Sampling: measuring the continuous signal's value every T units of time Shown in Frequency domain EEC-484/584: Computer Networks

  45. Nyquist Theorem • Max data rate = 2H log2V bits/sec, where signal consists of V discrete levels • Ex: H = 3000 Hz, V = 2 (binary)max data rate = 2*3000*log22 = 6000 bits/sec • Ex: H = 3000 Hz, V = 64max data rate = 2*3000*log264 = 36,000 bits/sec EEC-484/584: Computer Networks

  46. Shannon Theorem • For noisy channels: actual medium has thermal noise • Max data rate = H log2(1+S/N) bits/sec • Signal to noise ratio = signal power / noise power = S/N • Often use decibel (dB) as unit for S/N: 10 log10S/N • Ex: H = 3000 Hz, S/N = 30dB = 1000max data rate = 3000*log2(1+1000) = 30,000upper bound is hard to reach, 9600 bits/sec is good EEC-484/584: Computer Networks

  47. Optional Homework • Q1. Television channels are 6 MHz wide. How many bits/sec can be sent if four-level digital signals are used? Assume a noiseless channel. • Q2. A noiseless 4-kHz channel is sampled every 1 msec. What is the maximum data rate? (Assuming each sample is 16 bits) EEC-484/584: Computer Networks

  48. Optional Homework • Q3. What signal-to-noise ratio is needed to put a T1 carrier (1.544 Mbps) on a 50-kHz line? • Q4. If a binary signal is sent over a 3-kHz channel whose signal-to-noise ratio is 20 dB, what is the maximum achievable data rate? EEC-484/584: Computer Networks

More Related