julia ljunbjörk and anita mugenyi. what is a socket? like a house between the layers

Post on 23-Dec-2015

212 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Socket Programming with TCP and UDP

Julia Ljunbjörk and Anita Mugenyi

What is a socket?Like a houseBetween the layers

Socket programmingClient –serverTwo ways

Socket programming1. A client reads a line from its standard input

(keyboard) and sends the line out its socket to the server

2. The server reads a line from its socket3. The server converts the line to uppercase4. The server sends the modified line out its

socket to the client5. The client reads the modified line from its

socket and prints the line on its standard output(monitor)

process

TCP withbuffers,variables

socket

host orserver

process

TCP withbuffers,variables

socket

host orserver

Internet

controlled byapp developer

Socket programming with TCPReliable, byte stream-oriented Three-way handshakeThree socketsStreams

wait for incomingconnection requestconnectionSocket =welcomeSocket.accept()

create socket,port=x, forincoming request:welcomeSocket =

ServerSocket()

create socket,connect to hostid, port=xclientSocket =

Socket()

closeconnectionSocket

read reply fromclientSocket

closeclientSocket

Server (running on hostid) Client

send request usingclientSocketread request from

connectionSocket

write reply toconnectionSocket

TCP connection setup

Socket programming with UDPNo streamsNo connectionDatagram socketIndividual packets

Server (running on hostid)

closeclientSocket

read datagram fromclientSocket

create socket,clientSocket = DatagramSocket()

Client

Create datagram with server IP andport=x; send datagram via clientSocket

create socket,port= x.serverSocket = DatagramSocket()

read datagram fromserverSocket

write reply toserverSocketspecifying client address,port number

Thank you for your time!

top related