email
play

Email Session 5 INST 346 Technologies, Infrastructure and - PowerPoint PPT Presentation

Email Session 5 INST 346 Technologies, Infrastructure and Architecture Muddiest Points Format of the HTTP messages What GET, HEAD, POST actually do Who creates proxy servers? How to create a Web server Goals for Today Finish


  1. Email Session 5 INST 346 Technologies, Infrastructure and Architecture

  2. Muddiest Points • Format of the HTTP messages – What GET, HEAD, POST actually do • Who creates proxy servers? • How to create a Web server

  3. Goals for Today • Finish Email – Review SMTP – POP3 and IMAP • Learn socket programming • Getahead: DNS (maybe!)

  4. Email outgoing message queue user mailbox Three major components: user agent  user agents (“mail reader”)  mail servers mail user server agent  simple mail transfer protocol: SMTP SMTP mail user server agent User Agent SMTP  composing, editing, reading user SMTP email messages agent mail server  e.g., Outlook, Thunderbird, user iPhone mail client agent  outgoing, incoming user messages stored on server agent

  5. Email: mail servers mail servers: user agent  mailbox contains incoming messages for user mail user server  message queue of outgoing agent (to be sent) mail messages SMTP mail user  SMTP protocol between server agent mail servers to send email SMTP messages user SMTP • client: sending mail agent mail server server • “ server ” : receiving mail user agent server user agent

  6. Email: SMTP [RFC 2821]  uses TCP to reliably transfer email message from client to server, port 25  direct transfer: sending server to receiving server  three phases of transfer • handshaking (greeting) • transfer messages • close  command/response interaction (like HTTP ) • commands: ASCII text • response: status code and phrase  messages must be in 7-bit ASCII

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

  8. Sample SMTP interaction Mail server (client) at crepes.fr has mail to send Client initiates connection to hamburger.edu port 25 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

  9. SMTP: final words comparison with HTTP:  SMTP uses persistent connections  HTTP: pull  SMTP requires message  SMTP: push (header & body) to be in 7-bit ASCII  both have ASCII  SMTP server uses command/response CRLF.CRLF to interaction, status codes determine end of message  HTTP: each object encapsulated in its own response message  SMTP: multiple objects sent in multipart message

  10. Mail message format SMTP: protocol for exchanging email messages header blank RFC 822: standard for text line message format:  header lines, e.g., • To: body • From: • Subject: different from SMTP MAIL FROM, RCPT TO: commands!  Body: the “ message ” • ASCII characters only

  11. Mail access protocols mail access user user SMTP SMTP protocol agent agent (e.g., POP, IMAP ) sender ’ s mail receiver ’ s mail server server  SMTP: delivery/storage to receiver ’ s mail server  mail access protocol: upload to and download from a mail server • POP: Post Office Protocol [RFC 1939]: authorization, download • IMAP: Internet Mail Access Protocol [RFC 1730]: more features, including manipulation of stored messages in folders on the mail server

  12. POP3 protocol S: +OK POP3 server ready C: user bob ussrid authorization phase S: +OK C: pass hungry password client commands:  S: +OK user successfully logged on • user: declare username • pass: password C: list S: 1 498  server responses S: 2 912 • +OK S: . • -ERR C: retr 1 transaction phase, client: S: <message 1 contents> S: . list: list message numbers  C: dele 1  retr: retrieve message by C: retr 2 number S: <message 1 contents> dele: delete  S: .  quit C: dele 2 C: quit S: +OK POP3 server signing off

  13. Comparing POP3 and IMAP more about POP3 IMAP  previous example uses  keeps all messages in one POP3 “ download and place: at server delete ” mode  allows user to organize • Bob cannot re-read e- messages in folders mail if he changes  keeps user state across client sessions:  POP3 “ download-and- • names of folders and keep ” : copies of messages mappings between on different clients message IDs and folder  POP3 is stateless across name sessions

  14. Socket programming goal: learn how to build client/server applications that communicate using sockets socket: outbox/inbox between application process and end-end-transport protocol application application socket controlled by process process app developer transport transport network controlled network by OS link link Internet physical physical

  15. Socket programming Two socket types for two transport services: • UDP: unreliable datagram • TCP: reliable, byte stream-oriented Application Example: 1. client reads a line of characters (data) from its keyboard and sends data to server 2. server receives the data and converts characters to uppercase 3. server sends modified data to client 4. client receives modified data and displays line on its screen

  16. Client/server socket interaction: UDP server (running on serverIP ) client create socket: create socket, port= x: clientSocket = serverSocket = socket(AF_INET,SOCK_DGRAM) socket(AF_INET,SOCK_DGRAM) Create datagram with server IP and port=x; send datagram via read datagram from clientSocket serverSocket write reply to read datagram from serverSocket clientSocket specifying client address, close port number clientSocket

  17. Example app: UDP client Python UDPClient include Python’s socket from socket import * library serverName = ‘ localhost ’ serverPort = 12000 create UDP socket for clientSocket = socket(AF_INET, server SOCK_DGRAM) get user keyboard message = input (’Input lowercase sentence:’) input Attach server name, port to clientSocket.sendto (message.encode(), message; send into socket (serverName, serverPort)) read reply characters from modifiedMessage, serverAddress = socket into string clientSocket.recvfrom(2048) print out received string print(modifiedMessage.decode()) and close socket clientSocket.close()

  18. Example app: UDP server Python UDPServer from socket import * serverPort = 12000 create UDP socket serverSocket = socket(AF_INET, SOCK_DGRAM) bind socket to local port serverSocket.bind(('', serverPort)) number 12000 print ( “ The server is ready to receive ” ) loop forever while True: Read from UDP socket into message, clientAddress = serverSocket.recvfrom(2048) message, getting client’s address (client IP and port) modifiedMessage = message.decode().upper() serverSocket.sendto(modifiedMessage.encode(), send upper case string back to this client clientAddress)

  19. Running Python • Install the latest Python 3 from: – https://www.python.org/downloads/ • Download the programs – Materials used in class link from schedule • Open two shell windows – On a PC, type “ cmd ” in the search box – On a Mac, open a terminal • In one shell, type: – python udpserver.py • In the other, type: – python udpclient.py

  20. Socket programming with TCP client must contact server  when contacted by client, server TCP creates new socket  server process must first be for server process to running communicate with that  server must have created particular client socket that welcomes • allows server to talk with client ’ s contact multiple clients client contacts server by: • source port numbers used  Creating TCP socket, to distinguish clients specifying IP address, port (more in Chap 3) number of server process application viewpoint:  when client creates socket: TCP provides reliable, in-order client TCP establishes connection to server TCP byte-stream transfer ( “ pipe ” ) between client and server

  21. Client/server socket interaction: TCP client server (running on hostid ) create socket, port= x , for incoming request: serverSocket = socket() wait for incoming create socket, TCP connect to hostid , port= x connection request connection setup connectionSocket = clientSocket = socket() serverSocket.accept() send request using read request from clientSocket connectionSocket write reply to connectionSocket read reply from clientSocket close close connectionSocket clientSocket

  22. Example app: TCP client Python TCPClient from socket import * serverName = ’ localhost ’ serverPort = 12000 create TCP socket for server, remote port 12000 clientSocket = socket(AF_INET, SOCK_STREAM) clientSocket.connect((serverName,serverPort)) sentence = input (‘Input lowercase sentence:’) No need to attach server clientSocket.send(sentence.encode()) name, port modifiedSentence = clientSocket.recv(1024) print (‘From Server:’, modifiedSentence.decode()) clientSocket.close()

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend