Unformatted text preview:

Data Communication and NetworksInternet transport-layer protocolsMultiplexing/demultiplexingHow demultiplexing worksConnectionless demultiplexingConnectionless demux (cont)Connection-oriented demuxConnection-oriented demux (cont)Socket programmingSocket-programming using TCPSocket programming with TCPStream jargonSlide 13Client/server socket interaction: TCPExample: Java client (TCP)Example: Java client (TCP), cont.Example: Java server (TCP)Example: Java server (TCP), contSocket programming with UDPClient/server socket interaction: UDPExample: Java client (UDP)Slide 22Example: Java client (UDP), cont.Example: Java server (UDP)Example: Java server (UDP), cont2: Application Layer 1Data Communication and NetworksLecture 11Java SocketsDecember 1, 20052: Application Layer 2Internet transport-layer protocolsreliable, in-order delivery TCPcongestion control flow controlconnection setupunreliable, unordered delivery: UDPno-frills extension of “best-effort” IPservices not available: delay guaranteesbandwidth guaranteesapplicationtransportnetworkdata linkphysicalapplicationtransportnetworkdata linkphysicalnetworkdata linkphysicalnetworkdata linkphysicalnetworkdata linkphysicalnetworkdata linkphysicalnetworkdata linkphysicallogical end-end transport2: Application Layer 3Multiplexing/demultiplexingapplicationtransportnetworklinkphysicalP1applicationtransportnetworklinkphysicalapplicationtransportnetworklinkphysicalP2P3P4P1host 1host 2host 3= process= socketdelivering received segmentsto correct socketDemultiplexing at rcv host:gathering data from multiplesockets, enveloping data with header (later used for demultiplexing)Multiplexing at send host:2: Application Layer 4How demultiplexing workshost receives IP datagramseach datagram has source IP address, destination IP addresseach datagram carries 1 transport-layer segmenteach segment has source, destination port number (recall: well-known port numbers for specific applications)host uses IP addresses & port numbers to direct segment to appropriate socketsource port # dest port #32 bitsapplicationdata (message)other header fieldsTCP/UDP segment format2: Application Layer 5Connectionless demultiplexingCreate sockets with port numbers:DatagramSocket mySocket1 = new DatagramSocket(99111);DatagramSocket mySocket2 = new DatagramSocket(99222);UDP socket identified by two-tuple:(dest IP address, dest port number)When host receives UDP segment:checks destination port number in segmentdirects UDP segment to socket with that port numberIP datagrams with different source IP addresses and/or source port numbers directed to same socket2: Application Layer 6Connectionless demux (cont)DatagramSocket serverSocket = new DatagramSocket(6428);ClientIP:BP2client IP: AP1P1P3serverIP: CSP: 6428DP: 9157SP: 9157DP: 6428SP: 6428DP: 5775SP: 5775DP: 6428SP provides “return address”2: Application Layer 7Connection-oriented demuxTCP socket identified by 4-tuple: source IP addresssource port numberdest IP addressdest port numberrecv host uses all four values to direct segment to appropriate socketServer host may support many simultaneous TCP sockets:each socket identified by its own 4-tupleWeb servers have different sockets for each connecting clientnon-persistent HTTP will have different socket for each request2: Application Layer 8Connection-oriented demux (cont)ClientIP:BP1client IP: AP1P2P4serverIP: CSP: 9157DP: 80SP: 9157DP: 80P5P6P3D-IP:CS-IP: AD-IP:CS-IP: BSP: 5775DP: 80D-IP:CS-IP: B2: Application Layer 9Socket programmingSocket APIintroduced in BSD4.1 UNIX, 1981explicitly created, used, released by apps client/server paradigm two types of transport service via socket API: unreliable datagram reliable, byte stream-oriented a host-local, application-created, OS-controlled interface (a “door”) into whichapplication process can both send and receive messages to/from another application processsocketGoal: learn how to build client/server application that communicate using sockets2: Application Layer 10Socket-programming using TCPSocket: a door between application process and end-end-transport protocol (UCP or TCP)TCP service: reliable transfer of bytes from one process to anotherprocessTCP withbuffers,variablessocketcontrolled byapplicationdevelopercontrolled byoperatingsystemhost orserverprocessTCP withbuffers,variablessocketcontrolled byapplicationdevelopercontrolled byoperatingsystemhost orserverinternet2: Application Layer 11Socket programming with TCPClient must contact serverserver process must first be runningserver must have created socket (door) that welcomes client’s contactClient 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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 (more in Chap 3)TCP provides reliable, in-order transfer of bytes (“pipe”) between client and serverapplication viewpoint2: Application Layer 12Stream jargon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, eg, keyboard or socket.An output stream is attached to an output source, eg, monitor or socket.2: Application Layer 13Socket programming with TCPExample client-server app:1) client reads line from standard input (inFromUser stream) , sends to server via socket (outToServer stream)2) server reads line from socket3) server converts line to uppercase, sends back to client4) client reads, prints modified line from socket (inFromServer stream)outToServerto network from networkinFromServerinFromUserkeyboard monitorProcessclientSocketinputstreaminputstreamoutputstreamTCPsocketClientprocessclient TCP socket2: Application Layer 14Client/server socket interaction: TCPwait for incomingconnection requestconnectionSocket =welcomeSocket.accept()create socket,port=x, forincoming request:welcomeSocket = ServerSocket()create socket,connect to hostid, port=xclientSocket = Socket()closeconnectionSocketread reply fromclientSocketcloseclientSocketServer (running on hostid)Clientsend request usingclientSocketread request fromconnectionSocketwrite reply toconnectionSocketTCP connection setup2:


View Full Document

NYU CSCI-GA 2262 - Java Sockets

Download Java Sockets
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Java Sockets and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Java Sockets 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?