Professional Documents
Culture Documents
Jaringan Komputer
(IKI-20240)
Acuan: Bab 1.4 Implementing Network Software
Johny Moningka
(moningka@cs.ui.ac.id)
Fakultas Ilmu Komputer
Universitas Indonesia
Semester 2003/2004
Versi: 1.1 2 Fasilkom UI v-1.1
Global IP Internet
Note: clients and servers are processes running on hosts
(can be the same or different hosts).
1
A Programmer’s View of the Internet Internet Connections
Identifikasi komputer (host) dipetakan dalam Clients and servers communicate by sending
bentuk alamat: 32-bit IP Address: streams of bytes over connections.
Contoh: 128.2.203.179 (notasi desimal utk 32 bit) Connections are point-to-point, full-duplex (2-
way communication), and reliable.
Kumpulan IP address selanjutnya dipetakan ke
identifikasi alamat domain yang lebih flexible: Client socket address Server socket address
128.2.194.242 : 51213 208.216.181.15 : 80
Internet domain names:
Contoh: 128.2.203.179 => www.cs.cmu.edu Server
Client
Connection socket pair (port 80)
(128.2.194.242:51213, 208.216.181.15:80)
Sebuah proses pada komputer dapat
Client host address Server host address
berhubungan dengan komputer lain melalui 128.2.194.242 208.216.181.15
“koneksi” pada jaringan Internet (menggunakan
Note: 51213 is an Note: 80 is a well-known port
identifikasi alamat di atas). port allocated associated with Web servers
by the kernel
7 Fasilkom UI v-1.1 8 Fasilkom UI v-1.1
2
Sockets
What is a socket?
To the kernel, a socket is an endpoint of
communication.
Socket Programming To an application, a socket is a file descriptor that
lets the application read/write from/to the network.
• Remember: All Unix I/O devices, including networks,
are modeled as files.
Jaringan Komputer Clients and servers communicate with each by
(IKI-20240) reading from and writing to socket descriptors.
Johny Moningka The main distinction between regular file I/O and
(moningka@cs.ui.ac.id)
socket I/O is how the application “opens” the
Fakultas Ilmu Komputer
Universitas Indonesia
socket descriptors.
Semester 2003/2004
Versi: 1.1 14 Fasilkom UI v-1.1
close() close()
Executed on the server Moves the socket from the CLOSED to the
Assign a (well-known) port address to the socket LISTEN state in the TCP state diagram – socket
Pertama: dibuat socket address is now ready to accept connections
int bind (int sockfd, const struct sockaddr
*myaddr, socklen_t addrlen) int listen (int sockfd, int backlog)
IP Address
Port Address
3
Server Initialization The connect() Call
Executes at Client
Establishes a connection with a server
Web Server int connect ( int sockfd,
1. socket()
const struct sockaddr
2. bind(80) *servaddr,
3. listen() socklen_t addrlen )
OS 80
Listen
queue
Listen
Request
queue
from (IP, port)
Creating a socket
int socket(int domain, int type, int protocol)
Web Server • domain = PF_INET, PF_UNIX
Connected • type = SOCK_STREAM, SOCK_DGRAM
Client requests socket accept()
get queued-up in
the listen queue OS 80 Passive Open (on server)
First-come first- Listen
int bind(int socket, struct sockaddr *addr, int
served queue addr_len)
int listen(int socket, int backlog)
int accept(int socket, struct sockaddr *addr, int
addr_len)
Client 1 Client 2 Client 3
23 Fasilkom UI v-1.1 24 Fasilkom UI v-1.1
4
Summary: Socket API (2) IP Addresses
29 Fasilkom UI v-1.1