This preview shows page 95 - 102 out of 105 pages.
Client reads a line of characters (data) from its keyboard and sends the data to the server.2.The server receives the data and converts characters to uppercase.3.The server sends the modified data to the client.4.The client receives the modified data and displays the line on its screen.
Application Layer 2-96Socket programming with UDPUDP: no “connection”between client & server❖no handshaking before sending data❖sender explicitly attaches IP destination address and port # to each packet❖rcvr extracts sender IP address and port# from received packetUDP: transmitted data may be lost or received out-of-orderApplication viewpoint:❖UDP provides unreliabletransfer of groups of bytes (“datagrams”) between client and server
Client/server socket interaction: UDPcloseclientSocketread datagram fromclientSocketcreate socket:clientSocket =socket(AF_INET,SOCK_DGRAM)Create datagram with server IP andport=x; send datagram viaclientSocketcreate socket, port= x:serverSocket =socket(AF_INET,SOCK_DGRAM)read datagram fromserverSocketwrite reply toserverSocketspecifying client address,port numberApplication 2-97server(runningonserverIP)client
Application Layer 2-98Example app: UDP clientfrom socket import *serverName = ‘hostname’serverPort = 12000clientSocket = socket(socket.AF_INET, socket.SOCK_DGRAM)message = raw_input(’Input lowercase sentence:’)clientSocket.sendto(message,(serverName, serverPort))modifiedMessage, serverAddress = clientSocket.recvfrom(2048)print modifiedMessageclientSocket.close()Python UDPClientinclude Python’s socket librarycreate UDP socket for serverget user keyboardinput Attach server name, port to message; send into socketprint out received string and close socketread reply characters fromsocket into string