networked system architectures
play

Networked System Architectures Session 28 INST 346 Technologies, - PowerPoint PPT Presentation

Networked System Architectures Session 28 INST 346 Technologies, Infrastructure and Architecture Goals for Today Internet Architectures Building an Internet app Creating a network app application transport network data link


  1. Networked System Architectures Session 28 INST 346 Technologies, Infrastructure and Architecture

  2. Goals for Today • Internet Architectures • Building an Internet app

  3. Creating a network app application transport network data link physical write programs that:  run on (different) end systems  communicate over network  e.g., web server software communicates with browser software no need to write software application transport network for network-core devices application data link transport physical network  network-core devices do not data link physical run user applications  applications on end systems allows for rapid app development, propagation

  4. Client-server architecture (e.g., Web) server:  always-on host  permanent IP address  data centers for scaling clients:  communicate with server  may be intermittently client/server connected  may have dynamic IP addresses  do not communicate directly with each other

  5. P2P architecture (e.g., Skype)  no central server peer-peer  arbitrary end systems directly communicate  peers request service from other peers, provide service in return to other peers • self scalability – new peers bring new service capacity, as well as new service demands  peers are intermittently connected and change IP addresses • complex management

  6. App-layer protocol must define:  types of messages • e.g., request, response  message syntax • what fields in messages • how fields are delineated  message semantics • meaning of information in fields  rules for when and how processes send & respond to messages “open” protocols:  e.g., HTTP, SMTP  defined in “Requests for Comment” (RFC’s)  designed for interoperability proprietary protocols:  e.g., Skype

  7. 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 controlled network network by OS link Internet link physical physical

  8. 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

  9. 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

  10. 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()

  11. 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)

  12. 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

  13. 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

  14. 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

  15. 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()

  16. Example app: TCP server Python TCPServer from socket import * serverPort = 12000 create TCP welcoming serverSocket = socket(AF_INET,SOCK_STREAM) socket serverSocket.bind((‘’,serverPort)) server begins listening for serverSocket.listen(1) incoming TCP requests print(‘The server is ready to receive’) loop forever while True: server waits on accept() connectionSocket, addr = serverSocket.accept() for incoming requests, new socket created on return sentence = connectionSocket.recv(1024).decode() read bytes from socket (but capitalizedSentence = sentence.upper() not address as in UDP) connectionSocket.send(capitalizedSentence. close connection to this client (but not welcoming encode()) socket) connectionSocket.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