Clientserver socket interaction TCP wait for incoming connection request

Clientserver socket interaction tcp wait for incoming

This preview shows page 101 - 105 out of 105 pages.

Client/server socket interaction: TCP wait for incoming connection request connectionSocket = serverSocket.accept() create socket, port= x , for incoming request: serverSocket = socket() create socket, connect to hostid , port= x clientSocket = socket() server (running on hostid ) client send request using clientSocket read request from connectionSocke t write reply to connectionSocket TCP connection setup close connectionSocket read reply from clientSocket close clientSocket
Image of page 101
Application Layer 2-102 Example app: TCP client from socket import * serverName = ’servername’ serverPort = 12000 clientSocket = socket(AF_INET, SOCK_STREAM) clientSocket.connect((serverName,serverPort)) sentence = raw_input(‘Input lowercase sentence:’) clientSocket.send(sentence) modifiedSentence = clientSocket.recv(1024) print ‘From Server:’, modifiedSentence clientSocket.close() Python TCPClient create TCP socket for server, remote port 12000 No need to attach server name, port
Image of page 102
Application Layer 2-103 Example app: TCP server from socket import * serverPort = 12000 serverSocket = socket(AF_INET,SOCK_STREAM) serverSocket.bind((‘’,serverPort)) serverSocket.listen(1) print ‘The server is ready to receive’ while 1: connectionSocket, addr = serverSocket.accept() sentence = connectionSocket.recv(1024) capitalizedSentence = sentence.upper() connectionSocket.send(capitalizedSentence) connectionSocket.close() Python TCPServer create TCP welcoming socket server begins listening for incoming TCP requests loop forever server waits on accept() for incoming requests, new socket created on return read bytes from socket (but not address as in UDP) close connection to this client (but not welcoming socket)
Image of page 103
Application Layer 2-104 Chapter 2: summary application architectures client-server P2P application service requirements: reliability, bandwidth, delay Internet transport service model connection-oriented, reliable: TCP unreliable, datagrams: UDP our study of network apps now complete! specific protocols: HTTP FTP SMTP, POP, IMAP DNS P2P: BitTorrent, DHT socket programming: TCP, UDP sockets
Image of page 104
Application Layer 2-105 typical request/reply message exchange: client requests info or service server responds with data, status code message formats: headers: fields giving info about data data: info being communicated important themes: control vs. data msgs in-band, out-of-band centralized vs. decentralized stateless vs. stateful reliable vs. unreliable msg transfer complexity at network edge Chapter 2: summary most importantly: learned about protocols!
Image of page 105

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture