Beruflich Dokumente
Kultur Dokumente
z exchange messages to
implement application
z message format and
actions to be taken are
defined by application-
layer protocols
z uses services provided application
application
transport
transport
by lower layer protocols network
network
data link
data link physical
z Typical network app has physical
Client-server paradigm
Client:
application
z a program running on the local transport
network
machine requesting service data link
physical
from a server.
z initiates contact with server by request
using the well-known port of the
requested services
z e.g. Web client requests a Web
page
reply
Server:
z a program running infinitely on application
transport
the remote machine providing network
data link
service to the clients. physical
controlled by UA UA
application
developer Process Process
socket socket
controlled by Transport Internet Transport
operating system service service
Host or client Host or server
controlled by UA UA
application
developer Process Process
socket socket
controlled by Transport Internet Transport
operating system service service
Host or client Host or server
Server types:
z Iterative server
it can handle only one request at a time
other requests have to wait
z Concurrent server
handles several requests concurrently
Server Listening
socket
{*:21, *:*}
Client
Connection request to
Server Listening
206.62.226.35, port 21 socket
{198.69.10.2:1500, {*:21, *:*}
206.62.226.35:21}
Client Listening
Server socket
{198.69.10.2:1500, con
206.62.226.35:21}
n ect {*:21, *:*}
ion
fork
Server Connected
(Child) socket
{206.62.226.35:21,
198.69.10.2:1500}
198.69.10.2 206.62.226.35
Listening
Client1 Server socket
{198.69.10.2:1500, con {*:21, *:*}
206.62.226.35:21} ne ctio
n fork
Client2 Server Connected
(Child) socket
{198.69.10.2:1501, con
206.62.226.35:21}
ne ctio
n {206.62.226.35:21,
198.69.10.2:1500}
Server Connected
(Child) socket
{206.62.226.35:21,
198.69.10.2:1501}
Socket programming:
z Means building client/server applications that
communicate using sockets.
controlled by UA UA
application
developer Process Process
socket socket
controlled by Transport Internet Transport
operating system service service
Host or client Host or server
z Socket:
defines interface between application and transport layer.
is created by the application and controlled by the OS.
two processes communicate by sending data into socket,
reading data out of socket.
CSC4430 – Data Communication and Computer Networks 18
20.3. Socket Programming
Socket API:
z Introduced in BSD4.1 UNIX in 1981.
z Two types of transport service via socket API:
UDP – unreliable datagram (connectionless).
TCP – reliable, byte stream-oriented (connection-
oriented).
z Socket:
Datagram socket = UDP socket.
Stream socket = TCP socket.
z Socket address = IP address + port number.
write reply to
connectionSocket read reply from
clientSocket
close
connectionSocket close
clientSocket
Iterative server
ServerSocket welcomeSocket = new ServerSocket(6789);
while(true) {
Socket connectionSocket = welcomeSocket.accept(); // new request
… // processes the request
}
Concurrent server
while(true) {
Socket connectionSocket = welcomeSocket.accept(); // new request
A newServerThread(connectionSocket);
}
class ServerThread extends Thread {
B public ServerThread(Socket s) {
….
start(); // calls run()
}
C public void run() {
… // processes the request
}
}
write reply to
serverSocket
specifying client read reply from
host address, clientSocket
port umber close
clientSocket