Chapter 1 - Introduction

Download Report

Transcript Chapter 1 - Introduction

Computer Networks and Internets, 5e
By Douglas E. Comer
Lecture PowerPoints
By Lami Kaya, [email protected]
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
1
Chapter 3
Internet Uygulamaları
ve
Ağ Programcılığı
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
2
Anlatılacak Konular
•
•
•
•
•
•
•
•
•
•
•
•
•
3.1 Giriş
3.2 internet İletişiminde İki Temel Paradigma
3.3 Bağlantı Tabanlı (Connection-Oriented) İletişim
3.4 İstemci – Sunucu (Client-Server) etkileşim modeli
3.5 İstemci – Sunucuların Özellikleri
3.6 Sunucu Programları ve Sunucu Sınıfı Bilgisayarları
3.7 İstekler (Requests), Cevaplar (Responses), ve Veri Akışı yönü
3.8 Çok İstemci ve Çok Sunucular
3.9 Sunucu(Server) Belirleme ve Çoğullama (Demultiplexing)
3.10 Eşzamanlı Sunucular
3.11 Sunucular Arasında Dairesel Bağımlılıklar
3.12 Peer-to-Peer etkileşimler Peer-to-Peer etkileşimler
3.13 Ağ Programcılığı ve Socket API
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
3
Anlatılacak Konular
•
•
•
•
•
•
•
•
•
3.14 Socketler, Açıklayıcılar (Descriptors), ve Ağ I/O
3.15 Socket API’si ve parametreleri
3.16 İstemci ve Sunuculardaki Socket Çağrımları
3.17 İstemci ve Sunucularındaki kullanılalan Socket
fonksiyonları
3.18 İstemci’de kullanılan bağlantı fonksiyonları
3.19 Sunucu’da kullanılan bağlantı fonksiyonları
3.20 Mesaj paradigmasında kullanılan Socket Fonksiyonları
3.21 Diğer Socket Fonksiyonları
3.22 Sockets, Threads, ve Inheritance
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
4
3.1 Introduction
• The Internet offers users a rich diversity of services
– none of the services is part of the underlying communication
infrastructure
• Internet provides a general purpose mechanism on which
– all services are built
– and individual services are supplied by application programs that run
on computers attached to the Internet
• It is possible to devise new services without changing the
Internet
• Chapter covers two key concepts of Internet applications:
– describes the conceptual paradigm that applications follow when
they communicate over the Internet
– presents the details of the socket Application Programming Interface
(socket API) that Internet applications use
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
5
3.1 Giriş
• Internet, kullanıcılara çeşitli zengin servisler sunuyor
– Bu servislerden hiçbiri temelde iletişim altyapısında değildir
• Internet genel amaçlı mekanizma sağlar
– Bütün servislerin inşa edilmesi
– Ve Bağımsız servisler, internete bağalanan uygulama programları
tarafından sağlanır
• Internet’i değitirmeden yeni servisler geliştirilebilir
• Bu bölüm Internet uygulamalarının iki temel anahtar
konseptini içerir:
– Internette iletişime geçerken uygulanacak kavramsal paradigmaları
açıklar
– Internet uygulamalarının kullandığı socket API ( Application
Programming Interface ) detayları ile sunmak
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
6
3.1 Introduction
• Internet application programmers can get started easily
• It is possible to create Internet applications without knowing
how networks operate
– However, understanding network protocols and technologies allows
them to write efficient and reliable code that enables applications to
scale across many sites
• Later parts of the text provide the necessary information by
explaining data communications and protocols used to form
the Internet
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
7
3.1 Giriş
• Internet uygulamalarının programlanmasını kolayca
başlanabilir
• Ağ’ın çalışma sistemini bilmeden Internet uygulamaları
geliştirmek mümkündür
– Fakat, ağ protokolleri ve teknolojilerinin izin verdiği ölçüde etkin ve
güvenilir kod geliştirilmesinin anlanılması gerekir.
• Budan sonraki bölümlerde, Internetteki veri iletişiminde ve
protokollerinde gerekli olan bilgilerin açıklanması
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
8
3.2 Two Basic Internet Communication
Paradigms
• The Internet supports two basic communication paradigms:
– 3.2.1 Stream Transport in the Internet
– 3.2.2 Message Transport in the Internet
• Figure 3.1 summarizes the differences
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
9
3.2 Internet İletişiminde İki Temel
Paradigma
Internet iki temel iletişim paradigmasını destekler:
– 3.2.1 Internetteki Stream taşınması
– 3.2.2 Internetteki Message taşınması
• Şekil 3.1 farklılıkları özetler
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
10
3.2.1 Stream Transport in the Internet
•
•
•
•
•
Stream denotes a paradigm in which a sequence of bytes
flows from one application program to another
Internet's mechanism arranges two streams between a pair
of communicating applications, one in each direction
The network accepts input from either application, and
delivers the data to the other application
A sending application can choose to generate one byte at a
time, or can generate blocks of bytes
The network chooses the number of bytes to deliver at any
time
– the network can choose to combine smaller blocks into one large
block or can divide a large block into smaller blocks
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
11
3.2.1 Internetteki Stream taşınması
• Stream, bir uygulama programından diğerine olan akışı byte
dizilerini seklinde sembolize eder.
• Internet mekanizması her iletişim uygulamaları için iki çift
stream düzenler
• Ağ, uygulamadan girdi kabul edebilir, ve başka uygulamara
veri gönderimi yapabilir
• Gönderen program her zaman aralığında bir byte bilgi, yada
bir block bilgi gönderebilir
• Ağ belirli zaman aralığında veri bloğu gönderimini seçer
– Ağ küçük blokların bir büyük blok şeklinde gönderilimini yada büyük
bir bloğun daha küüçük bir blok şeklinde gönderimini seçebilir.
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
12
3.2.2 Message Transport in the Internet
• In a message paradigm, the network accepts and delivers
messages
• Each message delivered to a receiver corresponds to a
message that was transmitted by a sender
– the network never delivers part of a message, nor does it join
multiple messages together
– if a sender places exactly n bytes in an outgoing message, the
receiver will find exactly n bytes in the incoming message
• The message paradigm allows delivery in different forms:
– Unicast
• a message can be sent from an application on one computer directly to an
application on another, 1-to-1
– Multicast
• a message can be multicast to some of the computers on a network, 1-tomany
– Broadcast
• a message can be broadcast to all computers on a given network, 1-to-all
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
13
3.2.2 Internet üzerinden Mesaj taşınması
• Mesaj paradigması içerisinde, Ağ mesaj gönderimi ve
alımına izin verir
• Her gönderici tarafından gönderilen mesaj alıcısına iletilir
– Ağ hiçbir zaman mesajın sadece bir bölümünü, yada gönderilen bir
sürü mesajın birleştirilmesi işlemini gerçekleştirmez
– Eğer gönderen toplamda n byte göndermişse, alıcı tarafında da n
bye şeklinde alınır.
• Mesaj paradigması farklı şekillerde gönderime izin
vermektedir:
– Unicast
• Bir bilgisayardaki uygulama direkt olarak başka bilgisayardaki uygulamaya
mesaj gönderilmesi olayına deniyor, 1-to-1
– Multicast
• Mesaj ağ üzerinden bir sürü bilgisayara multicast edilebilmesi, 1-to-many
– Broadcast
• Mesaj ağ üzerindeki bütün bilgisayarlara multicast edilebilmesi, 1-to-all
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
14
3.2.2 Message Transport in the Internet
• Message service does not make any guarantees
• So messages may be
– Lost (i.e., never delivered)
– Duplicated (more than one copy arrives)
– Delivered out-of-order
• A programmer who uses the message paradigm must
insure that the application operates correctly
– even if packets are lost or reordered
• Most applications require delivery guarantees
• Programmers tend to use the stream service except in
special situations
– such as video, where multicast is needed and the application
provides support to handle packet reordering and loss
• Thus, we will focus on the stream paradigm
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
15
3.2.2 Internet üzerinden Mesaj taşınması
• Mesaj servisleri garanti veremezler
• Bu yüzden mesajlar
– Kaybolabilir (Lost) (i.e., hiçbir zaman iletilemeyebilir)
– Kopyalanabilir (Duplicated) (birden fazla kopyası ulaşabilir)
– Sırasız bir şekilde iletilebilir out-of-order
• Mesaj paradigmasını kullanan programcı uygulamanın
doğru çalıştığının garantisini verebilmeli
– paketler yeniden sıralanması gerekse yada kaybolsa bile
• Çoğu uygulamaların iletilme garantisine ihtiyaç duyarlar
• Programcılar stream servisinin kullanmaya meyletmeli, bazı
özel durumlar hariç
– Örnek verecek olursak video,çünkü multicast gerektirebilir aynı
zamanda paket kayıpları yada yeniden sıralandırmayı desteğinin
sağlanması gerekir.
• Böylece, biz stream paradigması üzerinde duracağız.
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
16
3.3 Connection-Oriented Communication
• The Internet stream service is connection-oriented
• It operates analogous to a telephone call:
– two applications must request that a connection be created
– once it has been established, the connection allows the applications
to send data in either direction
– finally, when they finish communicating, the applications request that
the connection be terminated
• Algorithm 3.1 summarizes the interaction
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
17
3.3 Bağlantı Tabanlı (Connection-Oriented) İletişim
• Internetteki stream servisleri bağlantı tabanlıdır (connection-oriented )
• Analog telefon çağrısı gibi çalışır:
– İki uygulamada bağlantının kurulmasını talep etmek zorundadır
– Bağlantı kurulduktan sonra, bağlantı uygulamaların her yöne veri
göndermeleleri izin verir
– Son olarak, iletişimi bitirdikten sonra, uygulamalar bağlantının
sonlandırılmasını talep edebilirler
• Şekil 3.1 deki algoritma etkileşimi özetler
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
18
3.4 The Client-Server Model of Interaction
• The first step in Algorithm 3.1 raises a question:
– how can a pair of applications that run on two independent
computers coordinate to guarantee that they request a connection at
the same time?
• The answer lies in a form of interaction known as the clientserver model
– A server starts first and awaits contact
– A client starts second and initiates the connection
• Figure 3.2 summarizes the interaction
• Subsequent sections describe how specific services use the
client-server model
• Application programs known as clients and servers handle
all services in the Internet
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
19
3.4 İstemci – Sunucu (Client-Server) etkileşim modeli
• 3.1 deki algoritmanın ilk adımı bir soru sorulmasını
gerektiriyor
– İki farklı makinede çalışan iki farklı uygulama nasıl aynı zamanda
bağlantı isteğinin kordinasyonu garanti edebilirler?
• Cevap olarak istemci-sunucu modeli gösterilir
– Sunucu ilk olarak bağlantı gözlemekle işe başlar
– İstemci ikinci olarak çalışır ve bağlantının başlatır
• Şekil 3.2 etkileşimi özetler
• Sonraki bölümler istemci-sunucu modelinde nasıl spesifik
servislerin kullanımını açıklar
• Interneteki bütün servisler istemci ve sunucu uygulama
programları olarak bilinir
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
20
3.4 İstemci – Sunucu (Client-Server) etkileşim modeli
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
21
3.5 Characteristics of Clients and
Servers
• Most instances of client-server interaction have the same
general characteristics
• A client software:
– Is an arbitrary application program that becomes a client temporarily
when remote access is needed, but also performs other computation
– Is invoked directly by a user, and executes only for one session
– Runs locally on a user's personal computer
– Actively initiates contact with a server
– Can access multiple services as needed, but usually contacts one
remote server at a time
– Does not require especially powerful computer hardware
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
22
3.5 İstemci – Sunucuların Özellikleri
• Birçok istemci ve sunucu etkileşimi örnekleri aynı genel
özelliklere sahiptir.
• İstemci yazılımı:
– Uzaktaki bir servise ulaşmak için istemci üzerinde çalışan uygulama
programı geçici olarak bağlantı kurmak isteyebilir
– Çağırım direkt olarak kullanıcı tarafından mı gerçekleştirilir? Sadece
bir oturum(session) için mi çalıştırılır
– Kullanıcının kişisel bilgisayarında lokal olarak çalışır
– Sunucuya aktif olarak bağlantıyı başlatır
– Gerekli ulan birden fazla servise ulaşabilir, fakat genelde bir sunucu
ile haberleşir
– Güçlü Bilgisayar Donanımı gerektirmez
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
23
3.5 Characteristics of Clients and
Servers
• A server software:
– Is a special-purpose, privileged program
– Is dedicated to providing one service that can handle multiple remote
clients at the same time
– Is invoked automatically when a system boots, and continues to
execute through many sessions
– Runs on a large, powerful computer
– Waits passively for contact from arbitrary remote clients
– Accepts contact from arbitrary clients, but offers a single service
– Requires powerful hardware and a sophisticated operating system
(OS)
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
24
3.5 İstemci – Sunucuların Özellikleri
• Sunucu Yazılımı:
– Özel amaçlı, öncelikli (privileged ) program
– Aynı zamandan birden fazla istemciye bir servis hizmeti sağlar
– Is invoked automatically when a system boots, and continues to
execute through many sessions
– Büyük ve Güçlü bilgisayarlar üzerinde çalışır
– Gelişigüzel etkileşimde bulunan istemciler pasif olarak bekler
– İstemcilerin Gelişigüzel etkileşimlerini kabul eder, fakat tekbir servis
sunar
– Çok güşlü donanım ve kendilerine özgü işletim sistelerine ihtiyaç
duyarlar
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
25
3.6 Server Programs and Server-Class
Computers
• Term server refers to a program that waits passively for
communication
• However, when a computer is dedicated to running one or
more server programs,
– the computer itself is sometimes called a server
• Hardware vendors contribute to the confusion
– because they classify computers that have fast CPUs, large
memories, and powerful operating systems as server machines
• Figure 3.3 illustrates the definitions
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
26
3.6 Sunucu Programları ve Sunucu Sınıfı
Bilgisayarları
• Sunucu ismi programın bağlantı için pasif olarak beklediğini
göstermek için verilmiştir
• Fakat, Bilgisayar bir yada daha fazla sunucu programı
çalıştırmak için adandığı zaman
– O zaman bilgisayarın kendisine Sunucu deniyor
• Donanım satıcıları bu kafa karışıklığına katıldılar
– Çünkü, Hızlı CPUlu, büyük hafızaya sahip ve güçlü işletim sistemine
sahip Makinaları Sunucu diye sınıflandırdılar
• Şekil 3.3 Bu tanımlamayı gösteriyor
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
27
3.6 Sunucu Programları ve Sunucu Sınıfı
Bilgisayarları
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
28
3.7 Requests, Responses, and Direction of Data Flow
• Client and server?
• Which side initiates contact?
• Once contact has been established, two-way
communication is possible (i.e., data can flow from a client
to a server or from a server to a client)
• In some cases, a client sends a series of requests and the
server issues a series of responses (e.g., a database client
might allow a user to look up more than one item at a time)
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
29
3.7 İstekler (Requests), Cevaplar (Responses), ve
Veri Akışı yönü
• İstemci ve Sunucu?
• Hangi taraf bağlatıyı başlatır
• Bir kere bağlantı gerçekleştimi, iki-yönlü iletişim
gerçekleştirilebilir. (Veri istemciden sunucuya yada
sunucudan istemciye doğru akabilir)
• Bazı durumlarda, istemci seri şeklinde(series of requests )
istek gönderebilir buna karşılık sunucuda seri şeklinde
cevaplar verebilir(series of responses ) (Örnek olarak,
veritabanına istemci birden fazla maddeyi görmek için
istekte bulunabilir)
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
30
3.8 Multiple Clients and Multiple Servers
• Allowing a given computer to operate multiple servers is
useful because
– the hardware can be shared
– a single computer has lower system administration overhead than
multiple computer systems
– experience has shown that the demand for a server is often sporadic
• a server can remain idle for long periods of time
• an idle server does not use the CPU while waiting for a request to arrive
• If demand for services is low, consolidating servers on a
single computer can dramatically reduce cost
– without significantly reducing performance
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
31
3.8 Çok İstemci ve Çok Sunucular
• Bir bilgisayarın birden fazla sunucu şeklinde çalışmasına
izin vermek önemlidir çünkü,
– Donanım paylaşılabilir
– Tek bir bilgisayarın yönetim overhead’i birçok bilgisayarınkinden
daha düşüktür
– Tecrübe tekbir sunucuya olan ihtiyacın düzensiz/seyrek bir durum
olduğunu göstermiştir
• Sunucu hiçbir iş yapmadan uzun süre boş durabilir
• Boş bir sunucunun istek beklerken CPU’sunu kullanmaz
• Eğer servislere olan ihtiyaş düşük ise,tek bir bilgisayar
üzerindeki sağlamlaştırıcı (consolidating ) sunucular maliyeti
dramatik olarak düşürebilir
– Performansı ciddi şekilde düşürmeden
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
32
3.8 Multiple Clients and Multiple Servers
• A computer can run:
–
–
–
–
–
A single client
A single server
Multiple copies of a client that contact a given server
Multiple clients that each contact a particular server
Multiple servers, each for a particular service
• Allowing a computer to operate multiple clients is useful
– because services can be accessed simultaneously
• For example, a user can have three (3) windows open
simultaneously running three (3) applications:
– one that retrieves and displays email
– another that connects to a chat service
– and a third running a web browser
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
33
3.8 Çok İstemci ve Çok Sunucular
• Bilgisayar Şu şekilde çalışabilir:
– Basit bir İstemci olarak
– Basit bir Sunucu olarak
– Varolan bir Sunucuya bağlantıya geçebilmek için birden fazla İstemci
kopyasını barındırabilir
– Özel sunucuya bağlantı kurabilen birden fazla istemci şeklinde
– Birden fazla sunucu, herbir özel servisler veren
• Bilgisayarın birden fazla istemci şeklinde çalışılmasına izin
verilmesi faydalıdır
– Çünkü sevisler eşzamanlı olaraj ulaşılabilirler
• Mesela Kullanıcı 3 farklı pencerede aynı anda 3 farklı
programı çalıştırabiliyor
– Birinden e-mail gönderilip alınabilir
– Diğerinden arkadaşlarıyla chat yapılabilir
– Ve en diğerinden web-browser ı çalıştırabilir
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
34
3.9 Server Identification and Demultiplexing
• How does a client identify a server?
• The Internet protocols divide identification into two pieces:
– An identifier for the computer on which a server runs
– An identifier for a service on the computer
• Identifying a computer?
– Each computer in the Internet is assigned a unique 32-bit identifier
known as an Internet Protocol address (IP address)
– A client must specify the server’s IP address
– To make server identification easy for humans, each computer is
also assigned a name, and the Domain Name System (DNS)
• described in Chapter 4 is used to translate a name into an address
– Thus, a user specifies a name such as www.cisco.com rather than
an integer address
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
35
3.9 Sunucu(Server) Belirleme ve Çoğullama
(Demultiplexing)
• İstemci Sunucuyu nasıl tanır/tanımlar?
• Internet protokolleri tanıma işlemini iki parçaya ayırmıştır:
– Sunucunun çalıştığı bilgisyarın tanımlanması/tanımlayıcısı
– Bilgisayarda çalışan servisin tanımlanması/tanımlayıcısı
• Bilgisayarı tanımlamak?
– Interneteki bütün bilgisayarlara 32-bitlik eşsiz bir tanımlayıcı olan
Internet Protokol Adresi(IP address) olarak bilinen IP adresi ile
tanımlanır.
– İstemci Sunucunun IP adresini belirtmek zorundadır
– Sunucuların tanımlanmasını kolaylaştırmak için, her bilgisyara bir
DNS Domain Name System tanımlanmıştır
• Bölüm 4 te açıklanacak, isimleri IP adresine dönüştürme işlemini yapıyor
– Böylece, böylece insanlar isim digital numaraların yerine,
www.cisco.com gibi isimler tanımlıyorlar
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
36
3.9 Server Identification and Demultiplexing
• Identifying a service?
– Each service available in the Internet is assigned a unique 16-bit
identifier known as a protocol port number (or port number)
• Examples, email  port number 25, and the web  port number 80
– When a server begins execution
• it registers with its local OS by specifying the port number for its service
– When a client contacts a remote server to request service
• the request contains a port number
– When a request arrives at a server
• software on the server uses the port number in the request to determine
which application on the server computer should handle the request
• Figure 3.4 summarizes the basic steps
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
37
3.9 Sunucu(Server) Belirleme ve Çoğullama
(Demultiplexing)
• Servisi Tanımlamak?
– Internette var olan servisleri tanımlamak için de eşsiz 19-bitlik
protokol port numarı olarak bilinen numaralar atanmıştır. (or port
number)
• Örnek olarak, e-mail->port numarası 25, ve web port numarası -> 80
– Sunucu çalışmaya başladığı zaman
• Lokal işletim sistemine kendi servisi için port numarasını kayıt yaptırır
– İstemci Sunucudan servis talebinde bulunduğu zaman
• İstekler port numarasını içerir
– İstek Sunucuya ulaştığı zaman
• Sunucu üzerindeki yazılım port numarasını isteği belirlemede kulanır, Suncu
üzerinde çalışan uygulama bu isteklere cevap verir
• Şekil 3.4 basit adımları özetlemiştir
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
38
3.9 Sunucu(Server) Belirleme ve Çoğullama
(Demultiplexing)
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
39
3.10 Concurrent Servers
• The steps in Figure 3.4 imply that a server handles one
client at a time
• Although a serial approach works in a few trivial cases, most
servers are concurrent
– That is, a server uses more than one thread of control
• Concurrent execution depends on the OS being used
• Concurrent server code is divided into two pieces
– a main program (thread)
– a handler
• The main thread accepts contact from a client and creates a
thread of control for the client
• Each thread of control interacts with a single client and runs
the handler code
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
40
3.10 Eşzamanlı Sunucular
• Şekil 3.4 görünen adımlar, Sunucun bir istemci için yapmış
olduğu işi gösterir
• Seri çalışma yaklaşımı sadece belirli bazı durumlar için
geçerlidir, ve birçok sunucu eşzamanlı olarak çalışır
(concurrent)
– Buda Sunucunun control için birden fazla thread kullanığını gösterir
• Eşzamanlı çalışma kullanılan işletim sistemine bağımlıdır
• Eş zamanlı Sunucular iki parçaya ayrılır
– Asıl program(thread)
– Ve idereci (handler)
• Asıl Thread istemci ile iletişimin kurulmasını sağlar ve
istemci için thread oluşturur
• Kontrol için kullanılan her thread bir istemci ile iletişime
geçer ve idare edeci kod olarak çalışır
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
41
3.10 Concurrent Servers
• After handling one client the thread terminates
• The main thread keeps the server alive after creating a
thread to handle a request
– the main thread waits for another request to arrive
• If N clients are simultaneously using a concurrent server,
N+1 threads will be running:
– the main thread (1) is waiting for additional requests
– and N threads are each interacting with a single client
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
42
3.10 Eşzamanlı Sunucular
• Bir istemcinin işlemi bitirildikten sonra thread sonlardırılır.
• Asıl (Main) Thread Sunucunun süsrekli çalışmasını sağlar,
asıl thread yeni threadlerin isteklere cevap vermesi için yeni
threadleri oluşturu
• Asıl thread diğer isteklerin gelmesi için beklemde durur
• Eğer N adet istemci eşzamanlı olarak concurrent Sunucuya
bağlanırsa, sistemde toplam N+1 adet thread çalışıyor
demektir.
– Asıl thread (1) yeni isteklere karşılık vermek için bekler
– N adet thread, herbiri bir istemci ile haberleşir.
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
43
3.11 Circular Dependencies Among Servers
• In practice, the distinction blurs because a server for one
service can act as a client for another
– For example, before it can fill in a web page, a web server may need
to become a client of a database
– A server may also become the client of a security service (e.g., to
verify that a client is allowed to access the service).
• Programmers must be careful to avoid circular
dependencies among servers
• The potential for circularity is especially high when services
are designed independently
– because no single programmer controls all servers
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
44
3.11 Sunucular Arasında Dairesel Bağımlılıklar
• Pratikte, farklılıklar net olarak görünemeyebilir çünkü bir
sunucu aynı anda başka bir servisin istemcisi olabilir.
– Mesela, Bir websitesini doldurmadan, web sunucusu veritabanının
istemcisi olabilir
– Sunucu aynı zamanda güvenlik servisinin istemcisi olabilir
(kullanıcının bu servise ulaşmasını izin verebilir)
• Programcı sunucular bu şekilde dairesel bağımlılıklardan
kurtulması noktasında dikkatli olmalıdır
• Servisler bağımsız olarak dizayn edildiği için potansiyel
olarak dairesel şeklinde olmaları yüksek ihtimaldir
– Çünkü bütün Sunucuları bir programcı kontrol etmiyor.
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
45
3.12 Peer-to-Peer Interactions
• If a single server provides a given service
– the network connection between the server and the Internet can
become a bottleneck
• Figure 3.5 illustrates the architecture
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
46
3.12 Peer-to-Peer Etkileşimler
• Eğer tek bir sunucu verilen servisi sağlıyorsa
– Sunucu arasında kalan ağ bağlantısı ve Internette darboğaz
(bottleneck) oluşabilir
• Şekil 3.5 Bu mimariyi gösterir
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
47
3.12 Peer-to-Peer Interactions
• Can Internet services be provided without creating a central
bottleneck?
– One way to avoid a bottleneck forms the basis of file sharing known
as a peer-to-peer (P2P) architecture
• The scheme avoids placing data on a central server
– data is distributed equally among a set of N servers
– and each client request is sent to the appropriate server
– a given server only provides 1/N of the data
• the amount of traffic between a server and the Internet is 1/N as much as in
the single-server architecture
• Server software can run on the same computers as clients
• Figure 3.6 illustrates the architecture
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
48
3.12 Peer-to-Peer Etkileşimler
• Internet servisleri merkezi darboğazlar oluşturmadan
sağlanabilir mi?
– Bunu yapmanın bir yolu, yani darboğazdan kaçınmak, basit olarak
peer-to-peer (P2P) mimarisi ile dosya paylaşımı yapmak ile
mümkündür.
• Bu planda, veriyi merkezi bir sunucuya koymaktan kaçınır
– Veri dağınık olarak eşitbüyüklükte N adet sunucuda saklanır
– Ve her istemcinin isteği gerekli sunucuya gönderilir
– Verilen Sunucu verinin sadece 1/N lik kısmını sağlar
• Sunucu ve Internet arasındaki trafik , tek-sunuculu mimarinin 1/N kadardır
• Server software can run on the same computers as clients
• Sunucu yazılımı, İstemcinin bilgisayarında çalışabilir
• Şekil 3.6 bu mimariyi gösterir
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
49
3.12 Peer-to-Peer Etkileşimler
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
50
3.13 Network Programming
and the Socket API
• The interface an application uses to specify communication
is known as an Application Program Interface (API)
– Appendix 1 contains a simplified API (with only seven functions)
• example code that demonstrates how such an API can be used to create
Internet applications, including a working web server
• Details of an API depend on the OS
• One particular API has emerged as the de facto standard for
software that communicates over the Internet
– known as the socket API, and commonly abbreviated sockets
• The socket API is available for many OS
– such as Microsoft's Windows systems
– as well as various UNIX systems, including Linux
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
51
3.13 Ağ Programcılığı ve Socket API
• Uygulamanın kullandığı spesifik iletişim arayüzü Application
Program Interface (API) olarak bilinir
– Appendix 1 basitleştirilmiş API’yi içerir (Sadece yedi fonksiyon
gösterilmiştir)
• Örnek kod bu API yi kullanarak nasıl bir internet uygulaması
geliştirilebileceğini gösterir, çalışan Web sunucusunuda içerir
• API nin detayları işletim sistemine bağımlıdır
• Özel bir API de facto standartı olarak ortaya çıkabilir,
böylelikle internette iletişim yazılımı olarak kullanılabilir
– Bilinen adı ile socket API, genel olarak soketler olarak bilinirler
• Soket API si hali hazırdaki birsürü İşletim sistemi için
mevcuttur
– mesela Microsoft Windows sistemi
– UNIX ve Linux sistemleri
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
52
3.14 Sockets, Descriptors, and Network I/O
• Because it was originally developed as part of the UNIX OS,
the socket API is integrated with I/O
• When an application creates a socket to use for Internet
– OS returns a small integer descriptor that identifies the socket
• The application then passes the descriptor as an argument
– when it calls functions to perform an operation on the socket (e.g., to
transfer data across the network or to receive data)
• In many OS, socket descriptors are integrated with other I/O
descriptors
– as a result, an application can use the read and write operations for
socket I/O or I/O to a file
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
53
3.14 Socketler, Açıklayıcılar (Descriptors), ve Ağ I/O
• Orjinal olarak UNIX OS bir parçası olarak geliştirilmiş ve I/O
sistemine socket API olarak entegre edilmiştir
• Uygulama internete bağlanmak için soket kullandığı zaman
– OS(işletim sistemi) soketi açıklayıcı küçük bir tamsayı döndürür
• Uygulama bu açıklayıcı bilgiyi argüman olarak geçirir
– Soket üzerinde çeşitli fonksiyonların çağrıldığı zaman(mesela ağ
üzerinde veri transferi yapmak)
• Birçok işletim sisteminde, soket tanımlayıcı diğer I/O
tanımlayıcılarına entegre edilmiştir.
– Sonuç olarak, uygulama akuma ve yazma işlemlerini soket I/O yada
I/O dan dosyaya yapabilir.
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
54
3.15 Parameters and the Socket API
• Socket programming differs from conventional I/O
• An application must specify many details, such as
– the address of a remote computer
– the protocol port number
– and whether the application will act as a client or as a server
• To avoid having a single socket function with many parameters,
designers of the socket API chose to define many functions
• An application creates a socket, and then invokes functions for details
• The advantage of the socket approach is that most functions have three
or fewer parameters
• The disadvantage is that a programmer must remember to call multiple
functions when using sockets
• Figure 3.7 summarizes key functions in the socket API
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
55
3.15 Socket API’si ve parametreleri
• Soket programla geleneksel I/O nunkinden farklıdır
• Uygulama detayları açıklamak zorundadır, mesela
– Uzaktaki bilgisayarın adresi
– Protokol port numarası
– Uygulama sunucu yada istemci olarak davranabilir
• Tek bir soket fonksiyonun bir sürü parametre ile birleştirilmesinden
kaçınılalıdır, soket API tasarımcıları bir sürü fonksiyon tanımlamayı
seçmişler
• Uygulama soket oluşturur, ve sonra detaylar için fonksiyonları çağırır.
• Soket yaklaşımının avantajı çoğu fonksiyon üç yada daha az parametre
ile çalışır
• The disadvantage is that a programmer must remember to call multiple
functions when using sockets
• Dezanvatajı ise, programcı soketi kullanmak için bir sürü fonksiyonu
hatırlamak zorunda
• Şekil 3.7 soket API’sinin asıl fonksiyonlarını gösteriyor
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
56
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
57
3.16 Socket Calls in a Client and Server
• Figure 3.8 illustrates the sequence of socket calls made by
a typical client and server that use a stream connection
– The client sends data first and the server waits to receive data
• In practice, some applications arrange for the server to send
first (i.e., send and recv are called in the reverse order)
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
58
3.16 İstemci ve Sunuculardaki Socket Çağrımları
• Şekil 3.8 soket çağırımlarının gösterimi yapılmıştır, burada
istemci ve sunucu stream bağlantısını kullanmaktadır
– İstemci ilk olarak veri gönderir ve sunucu veri bekliyor
• Pratikte, bazı uygulamalar ilk göndermek için sunucuda
sıraya dizilir ( mesela, send ve recv ters sıralı olarak bilinir)
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
59
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
60
3.17 Socket Functions Used by Both
Client and Server
• Readers are encouraged to check the book for the details of
these functions
–
–
–
–
–
3.17.1
3.17.2
3.17.3
3.17.4
3.17.5
The Socket Function
The Send Function
The Recv Function
Read and Write with Sockets
The Close Function
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
61
3.17 İstemci ve Sunucularındaki
kullanılalan Socket fonksiyonları
• Readers are encouraged to check the book for the details of
these functions
• Okuyucular ilgili fonksiyonların detayları için kitapba
bakabilirler
–
–
–
–
–
3.17.1
3.17.2
3.17.3
3.17.4
3.17.5
Socket Fonksiyonu
Send Fonksiyonu
Recv Fonksiyonu
Read ve Write Soketler
Close Fonksiyonu
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
62
3.18 The Connection Function Used
Only by a Client
• Clients call connect to establish a connection with a specific
server. The form is:
connect (socket, saddress, saddresslen)
• Argument socket is the descriptor of a socket to use for the
connection
• Readers are encouraged to check the book for the details
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
63
3.18 İstemci’de kullanılan bağlantı
fonksiyonları
• İstemciler, spesifik sunucuyla bağlantı kurmak için bğlantı
oluşrurlar
connect (socket, saddress, saddresslen)
• Argüman olarak kullanılan socket bağlantı için kullanılacak
sokettir
• Öğrenciler detaylar için kitaba bakmaları önerilir
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
64
3.19 Sunucu’da kullanılan bağlantı
fonksiyonları
• Readers are encouraged to check the book for the details of
these functions
– 3.19.1 The Bind Function
– 3.19.2 The Listen Function
– 3.19.3 The Accept Function
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
65
3.19 Socket Functions Used Only by a
Server
• Öğrenciler detaylar için kitaba bakmaları önerilir
– 3.19.1 Bind Fonksiyonu
– 3.19.2 Listen Fonksiyonu
– 3.19.3 Accept Fonksiyonu
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
66
3.20 Socket Functions Used with the
Message Paradigm
• The socket functions used to send and receive messages
are more complicated than those used with the stream
paradigm because many options are available
– For example, a sender can choose whether to store the recipient’s
address in the socket and merely send data or to specify the
recipient’s address each time a message is transmitted
• Readers are encouraged to check the book for the details
– 3.20.1 Sendto and Sendmsg Socket Functions
– 3.20.2 Recvfrom and Recvmsg Functions
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
67
3.20 Mesaj paradigmasında kullanılan
Socket Fonksiyonları
• Mesaj gönderim ve alımı için kullanılan soket fonksiyonları
bizim burada gösterdiğimizden daha karmaşıktır çünkü bir
sürü seçenekler söz konusudur.
– Mesela, gönderici belki mesajı alanın adresinin saklanmasını
isteyebilir (çünkü arasıra veri gönderimi yapacaktır) ,yada alıcının
adresini her defasında yeniden tanımlanmak istenebilir
• Öğrenciler detaylar için kitaba bakmaları önerilir
– 3.20.1 Sendto ve Sendmsg Socket Fonksiyonları
– 3.20.2 Recvfrom ve Recvmsg Fonksiyonları
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
68
3.21 Other Socket Functions
• The socket API contains a variety of support functions
–
–
–
–
–
–
getpeername
gethostname
setsockopt
getsockopt g
gethostbyname
gethostbyaddr
• Readers are encouraged to check the book for the details
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
69
3.21 Diğer Socket Fonksiyonları
• Soket API’si çeşitli derecede fonksiyonları destekler
–
–
–
–
–
–
getpeername
gethostname
setsockopt
getsockopt g
gethostbyname
gethostbyaddr
• Öğrenciler detaylar için kitaba bakmaları önerilir
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
70
3.22 Sockets, Threads, and Inheritance
• The socket API works well with concurrent servers
• Implementations of the socket API adhere to the following
inheritance principle:
– Each new thread that is created inherits a copy of all open sockets
from the thread that created it
– The socket implementation uses a reference count mechanism to
control each socket
– When a socket is first created
• the system sets the socket’s reference count to 1
• and the socket exists as long as the reference count remains positive.
– When a program creates an additional thread
• the thread inherits a pointer to each open socket the program owns
• and the system increments the reference count of each socket by 1
– When a thread calls close
• the system decrements the reference count for the socket
• if the reference count has reached zero, the socket is removed
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
71
3.22 Sockets, Threads, ve Inheritance
• Soket API si eşzamanlı sunucularda iyi çalışır
• Soket API sinin gerçekleştirilmesi aşağıdaki
kalıtım(inheritance ) prensiplerine bağlıdır:
– Oluşturulan her yeni thread kalıtım sayesinde açık olan soketlerin
hepsinin bir kopyasını alabilmeli
– Soket uygulaması, soketi kontrol etmek için sayı (count)
mekanizması referansını kullanır,
– Soket ilk oluşturulduğu zaman
• Sistem soketin sayısını (count) 1 e eşitler
• Ve soket sayı(count) değeri pozitif oldukça soket var olur , kapanmaz
– Program ek olarak yeni ek bir thread oluşturduğu zaman
• Thread programın sahip olduğu her soket işaretçiyi kalıtım vasıtası ile alır
• Ve, sistem sayı değerini 1 artırır
– Thread kapatılması için çağrılırsa
• Sistem sayı değerini azaltır
• Eğer soket değeri sıfır a eşitlenirse soket kaldırılır
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
72