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

10
Socket Programming with TCP and UDP Julia Ljunbjörk and Anita Mugenyi

Upload: ursula-brooks

Post on 23-Dec-2015

212 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Julia Ljunbjörk and Anita Mugenyi. What is a socket? Like a house Between the layers

Socket Programming with TCP and UDP

Julia Ljunbjörk and Anita Mugenyi

Page 2: Julia Ljunbjörk and Anita Mugenyi. What is a socket? Like a house Between the layers

What is a socket?Like a houseBetween the layers

Page 3: Julia Ljunbjörk and Anita Mugenyi. What is a socket? Like a house Between the layers

Socket programmingClient –serverTwo ways

Page 4: Julia Ljunbjörk and Anita Mugenyi. What is a socket? Like a house Between the layers

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)

Page 5: Julia Ljunbjörk and Anita Mugenyi. What is a socket? Like a house Between the layers

process

TCP withbuffers,variables

socket

host orserver

process

TCP withbuffers,variables

socket

host orserver

Internet

controlled byapp developer

Page 6: Julia Ljunbjörk and Anita Mugenyi. What is a socket? Like a house Between the layers

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

Page 7: Julia Ljunbjörk and Anita Mugenyi. What is a socket? Like a house Between the layers

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

Page 8: Julia Ljunbjörk and Anita Mugenyi. What is a socket? Like a house Between the layers

Socket programming with UDPNo streamsNo connectionDatagram socketIndividual packets

Page 9: Julia Ljunbjörk and Anita Mugenyi. What is a socket? Like a house Between the layers

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

Page 10: Julia Ljunbjörk and Anita Mugenyi. What is a socket? Like a house Between the layers

Thank you for your time!