vassil roussev [email protected]. 2 a socket is the basic remote communication abstraction provided...
TRANSCRIPT
![Page 2: Vassil Roussev vassil@cs.uno.edu. 2 A socket is the basic remote communication abstraction provided by the OS to processes. controlled by operating system](https://reader036.vdocument.in/reader036/viewer/2022082818/56649eb45503460f94bbc195/html5/thumbnails/2.jpg)
2
A socket is the basic remote communication abstraction provided by the OS to processes.
controlledby operating
system
controlled byapplicationdeveloper
controlledby operating
system
controlled byapplicationdeveloper
process
Host (end system)
Internet
process
Host (end system)
TCP/IPstack
TCP/IPstack
Network access is managed by the OS. OS provides a socket API to allow network communication
socket socket
![Page 3: Vassil Roussev vassil@cs.uno.edu. 2 A socket is the basic remote communication abstraction provided by the OS to processes. controlled by operating system](https://reader036.vdocument.in/reader036/viewer/2022082818/56649eb45503460f94bbc195/html5/thumbnails/3.jpg)
3
Socket Programming using TCP service
processwrite
readbytes
bytes
processread
writesocket socket
Application Viewpoint TCP provides reliable, in-order transfer of
a stream of bytes between two end points (processes).
Internet
Same interface as other stream I/O
(files, pipes, etc.).
Pair of pipes abstraction
![Page 4: Vassil Roussev vassil@cs.uno.edu. 2 A socket is the basic remote communication abstraction provided by the OS to processes. controlled by operating system](https://reader036.vdocument.in/reader036/viewer/2022082818/56649eb45503460f94bbc195/html5/thumbnails/4.jpg)
4
read
write
TCP communication is based on the client/server concept.
write
readbytes
bytes
Welcomingsocket
TCP Client
3-way handshake
Connectionsocket
Clientsocket
TCP Server
Server is started first &waits for connection
requests.
Client initiates connection via 3-way handshake. Once established, connection
is completely symmetrical.
![Page 5: Vassil Roussev vassil@cs.uno.edu. 2 A socket is the basic remote communication abstraction provided by the OS to processes. controlled by operating system](https://reader036.vdocument.in/reader036/viewer/2022082818/56649eb45503460f94bbc195/html5/thumbnails/5.jpg)
5
A port number is a 16-bit number that uniquely identifies a network process on a host.
Server binds to adesired port number
(welcoming socket).Client must know port
number to reach server.
Port PID
0000 ---
0021
0022
0025
0080
0631
…
…
…
…
Most standard services
have a default port:File Transfer
Secure Shell
Simple Mail Transfer
World Wide Web
Print Service
Client sockets use any available port >1023.
ftpd
sshd
smtpd
httpd
cupsd
bind()
![Page 6: Vassil Roussev vassil@cs.uno.edu. 2 A socket is the basic remote communication abstraction provided by the OS to processes. controlled by operating system](https://reader036.vdocument.in/reader036/viewer/2022082818/56649eb45503460f94bbc195/html5/thumbnails/6.jpg)
6
Network Addressing for Sockets
A B socket connection: <IP-hostA, portA, IP-hostB, portB>
DNSHost name:cook.cs.uno.edu
Mnemonic, logical ID
IP address:137.30.120.32
Unique, routable ID
process
socket
Host (end system)
Internet
process
socket
Host (end system)
TCP/IPstack
TCP/IPstack
processprocess
socket
Host (end system)
Internet
processprocess
socket
Host (end system)
TCP/IPstack
TCP/IPstack
Local process IDshostA hostB
![Page 7: Vassil Roussev vassil@cs.uno.edu. 2 A socket is the basic remote communication abstraction provided by the OS to processes. controlled by operating system](https://reader036.vdocument.in/reader036/viewer/2022082818/56649eb45503460f94bbc195/html5/thumbnails/7.jpg)
7
The CapsLock example service converts strings sent by clients to upper case.Protocol:
Client: Gets a line of text from the user via the system’s standard input
Client: Sends the line to the server over the network
Server: Receives the line from the clientServer: Converts it to uppercaseServer: Sends back the uppercase line
Client: Receives uppercase line from serverClient: Displays it via the system’s standard output
![Page 8: Vassil Roussev vassil@cs.uno.edu. 2 A socket is the basic remote communication abstraction provided by the OS to processes. controlled by operating system](https://reader036.vdocument.in/reader036/viewer/2022082818/56649eb45503460f94bbc195/html5/thumbnails/8.jpg)
8
Stream View of the Problem (Client)
Flash reviewInput stream:
– Sequence of bytes going into a process– E.g., from keyboard, file, socket
Output stream: – Sequence of bytes coming out of a process– E.g., to display, file, socket
Clientprocess
Std input
Clientsocket
inFromServer
outToServer
Standard output
![Page 9: Vassil Roussev vassil@cs.uno.edu. 2 A socket is the basic remote communication abstraction provided by the OS to processes. controlled by operating system](https://reader036.vdocument.in/reader036/viewer/2022082818/56649eb45503460f94bbc195/html5/thumbnails/9.jpg)
9
Client/Server Socket Interaction: TCP
Wait for incomingconnection requestconnectionSocket =welcomeSocket.accept()
Create socket for incoming requests, bind to port 6789
welcomeSocket = ServerSocket(6789, 5)
Create socket,connect to 137.30.120.32, port = 6789
clientSocket = new Socket(137.30.120.32, 6789)
CloseconnectionSocket
Read reply from clientSocket
Close clientSocket
Server (running on cook.cs.uno.edu) Client
Send request using clientSocketRead request fromconnectionSocket
Write reply toconnectionSocket
TCP connection setup
![Page 10: Vassil Roussev vassil@cs.uno.edu. 2 A socket is the basic remote communication abstraction provided by the OS to processes. controlled by operating system](https://reader036.vdocument.in/reader036/viewer/2022082818/56649eb45503460f94bbc195/html5/thumbnails/10.jpg)
10
processsend
recv
processrecv
sendsocket socket
Internet
Socket Programming using UDP service
Application Viewpoint UDP provides unreliable transfer of
groups of bytes—datagrams—between two end points (processes).
Not a stream interface
Each datagram addressed explicitly
(no connection).
No delivery guarantee!
![Page 11: Vassil Roussev vassil@cs.uno.edu. 2 A socket is the basic remote communication abstraction provided by the OS to processes. controlled by operating system](https://reader036.vdocument.in/reader036/viewer/2022082818/56649eb45503460f94bbc195/html5/thumbnails/11.jpg)
11
Client/Server Socket Interaction: UDP
close clientSocket
Server (running on cook.cs.uno.edu)
read reply from clientSocket
Create socket for sending requests:
clientSocket = DatagramSocket()
Client
Create, address (137.30.120.40,9876),send datagram request using clientSocket
Create socket for incoming request:
serverSocket = DatagramSocket(9876)
read request fromserverSocket
write reply toserverSocketspecifying clienthost address,port number
![Page 12: Vassil Roussev vassil@cs.uno.edu. 2 A socket is the basic remote communication abstraction provided by the OS to processes. controlled by operating system](https://reader036.vdocument.in/reader036/viewer/2022082818/56649eb45503460f94bbc195/html5/thumbnails/12.jpg)
12
TCP/UDP CapsLock Example Demos
gitlab: vroussev/csci4311-f14/code