Socket Programming with TCP and UDP Julia Ljunbjrk
Socket Programming with TCP and UDP Julia Ljunbjörk and Anita Mugenyi
What is a socket? �Like a house �Between the layers
Socket programming �Client –server �Two ways
Socket programming 1. 2. 3. 4. 5. A client reads a line from its standard input (keyboard) and sends the line out its socket to the server The server reads a line from its socket The server converts the line to uppercase The server sends the modified line out its socket to the client The client reads the modified line from its socket and prints the line on its standard output(monitor)
host or server process controlled by app developer process socket TCP with buffers, variables Internet
Socket programming with TCP �Reliable, byte stream-oriented �Three-way handshake �Three sockets �Streams
Server (running on hostid) Client create socket, port=x, for incoming request: welcome. Socket = Server. Socket() TCP wait for incoming connection request connection. Socket = welcome. Socket. accept() read request from connection. Socket write reply to connection. Socket close connection. Socket setup create socket, connect to hostid, port=x client. Socket = Socket() send request using client. Socket read reply from client. Socket close client. Socket
Socket programming with UDP �No streams �No connection �Datagram socket �Individual packets
Server (running on hostid) create socket, port= x. server. Socket = Datagram. Socket() read datagram from server. Socket write reply to server. Socket specifying client address, port number Client create socket, client. Socket = Datagram. Socket() Create datagram with server IP and port=x; send datagram via client. Socket read datagram from client. Socket close client. Socket
Thank you for your time!
- Slides: 10