0% menganggap dokumen ini bermanfaat (0 suara)
6 tayangan8 halaman

Introduction to Java Programming and Data Structures 2020 Ch33a

Dokumen ini membahas konsep dasar jaringan komputer, termasuk istilah TCP, IP, dan soket, serta cara membuat aplikasi client/server menggunakan Java. Selain itu, dijelaskan juga tentang port, jenis-jenisnya, dan perbedaan antara protokol TCP dan UDP. Proses komunikasi antara client dan server diilustrasikan melalui tahapan seperti bind, listen, connect, dan accept.

Diunggah oleh

Fauziah Zahrah
Hak Cipta
© © All Rights Reserved
Kami menangani hak cipta konten dengan serius. Jika Anda merasa konten ini milik Anda, ajukan klaim di sini.
Format Tersedia
Unduh sebagai PDF, TXT atau baca online di Scribd
0% menganggap dokumen ini bermanfaat (0 suara)
6 tayangan8 halaman

Introduction to Java Programming and Data Structures 2020 Ch33a

Dokumen ini membahas konsep dasar jaringan komputer, termasuk istilah TCP, IP, dan soket, serta cara membuat aplikasi client/server menggunakan Java. Selain itu, dijelaskan juga tentang port, jenis-jenisnya, dan perbedaan antara protokol TCP dan UDP. Proses komunikasi antara client dan server diilustrasikan melalui tahapan seperti bind, listen, connect, dan accept.

Diunggah oleh

Fauziah Zahrah
Hak Cipta
© © All Rights Reserved
Kami menangani hak cipta konten dengan serius. Jika Anda merasa konten ini milik Anda, ajukan klaim di sini.
Format Tersedia
Unduh sebagai PDF, TXT atau baca online di Scribd
Anda di halaman 1/ 8

NETWORKING CHAPTER 33

Objectives
 To explain the terms: TCP, IP, domain name, domain
name server, stream-based communications, and packet-
based communications (§33.2).
 To create servers using server sockets (§33.2.1) and
clients using client sockets (§33.2.2).
 To implement Java networking programs using stream
sockets (§33.2.3).
 To develop an example of a client/server application
(§33.2.4).
 To obtain Internet addresses using the InetAddress class
(§33.3).
 To develop servers for multiple clients (§33.4).
 To send and receive objects on a network (§33.5).
 To develop an interactive tic-tac-toe game played on the
Internet (§33.6).
tambahan materi Untuk membuat aplikasi yang dapat mengirim data melalui jaringan komputer kita membutuhkan suatu
interface yang disebut socket.
Dengan soket, aplikasi dapat dengan mudah mengirim atau menerima data dari dan/atau ke aplikasi
lainnya di jaringan komputer.
Dengan menggunakan soket, kita tidak perlu memahami detail dari sistem jaringan komputer.

Lalu apa itu soket?

Dapat dianalogikan bahwa soket itu adalah sebuah pesawat telepon yang membantu kita untuk
menghubungi orang lain di tempat lain yang terhubung dengan jaringan telepon.
Pesawat telepon sebagai end point = soket adalah end point pada jalur komunikasi sebuah jaringan
komputer.
Pesawat telepon membutuhkan nomor telepon + nomor ekstensi = soket membutuhkan alamat IP dari
komputer tujuan + nomor dari aplikasi (port3) atau service yang akan dituju.

3 Port dalam bahasa inggris berarti pintu, celah, atau lubang pada sistem yang ada di komputer atau mikro komputer yang berguna untuk jalur
transfer data. Jenis-jenis port pada sistem komputer terbagi menjadi dua yaitu :
 Port Fisik, yaitu suatu slot, soket, atau tempat colokan, yang ada di Kompter, Laptop atau perangkat keras lainnya yang berfungsi
sebagai penghubung antara komputer dan pralatan input-output seperti: printer, mouse, keyboard, dan lain-lain.
 Port Logikal (nonfisik), yaitu port yang digunakan untuk jalur transfer data dengan koneksi tanpa kabel dan biasa digunakan oleh
software-software.
Contoh port fisik:

port RJ-45
port power

port USB

port serial

port infrared

port VGA

port paralel
port HDMI

port PS/2 port audio


Melalui jaringan fisik, data melewati banyak jaringan komputer atau router sebelum sampai kepada
tujuan, seperti tampak pada gambar.

Dengan adanya soket, cara pandang programmer menjadi lebih sederhana.


Jadi aplikasi hanya berhubungan dengan soket dan untuk pengiriman data dilakukan oleh soket, dengan
meniadakan kerumitan tahapan bagaimana routing untuk mencapai tujuan, bagaimana encapsulasi-
decapsulasi data melalui beberapa lapisan (lapisan aplikasi transport, network, link dan fisik), dll.

Berikan deskripsi proses pengiriman data yang ditunjukkan pada gambar diatas …
Dengan soket, aplikasi yang kita buat hanya berhubungan dengan layer transport saja. Protocol yang
dipilih dapat menggunakan protokol UDP atau TCP yang merupakan bagian dari layer transport.

Komunikasi antara aplikasi di jaringan biasanya mendasarkan client server.


Satu aplikasi sebagai client dan satunya sebagai server. Apabila client yang meminta request pelayanan
ke server = client yang berinitiatif menghubungi server, sedangkan server sebagai pelayan untuk client
bersifat pasif = menunggu dihubungi atau dikoneksi oleh client.
Yang dimaksud client dan server disini adalah sebuah aplikasi dan bukan sebuah hardware.

Untuk menghubungi server, client harus mengetahui alamat IP dari server dan number port dari aplikasi
yang ada diserver. IP address untuk menuju ke alamat server, sedangkan number portnya digunakan
untuk menuju alamat aplikasi yang dijalankan pada server.
Dengan demikian, soket programming antara client server akan membutuhkan IP address, number port,
dan protokol TCP atau UDP.
Contoh dari number port: misalkan port 23 untuk layanan atau aplikasi telnet server, port 25 untuk mail
server, port 80 untuk web server. Jadi sebuah client web server akan menggunakan aplikasi dengan
number port 80.
Gambaran sebuah port: misalnya ada aplikasi pegadaian dengan nomor port 62 dipasang pada server.
Untuk menghubungi aplikasi pegadaian (server), maka client harus akses dengan nomor port yang
sama, yaitu aplikasi pegadaian (server) dengan port 62.
Contoh lainnya: aplikasi catur online dengan port 5000 dan diakses menggunakan web ada http dengan
port 80 dan chatting dg port 6000. (satu aplikasi dapat menggunakan beberapa port untuk menangani
berbagai jenis komunikasi jaringan)

Pembagian port di bagi menjadi 3 grup berdasarkan fungsinya, yaitu port well-known ports (0-1023),
registered ports (1024-49151), dan dynamic/private ports (49152-65535).
Di kelompok well-known ports, port sudah dipetakan penggunaannya, misalnya:
Port 21 (FTP): Digunakan untuk transfer file.
Port 22 (SSH): Digunakan untuk koneksi aman ke server.
Port 25 (SMTP): Digunakan untuk mengirim email.
Port 53 (DNS): Digunakan untuk menerjemahkan nama domain ke alamat IP.
Port 80 (HTTP): Digunakan untuk mengakses halaman web.
Port 110 (POP3): Digunakan untuk mengambil email.
Port 143 (IMAP): Digunakan untuk mengakses email.
Port 443 (HTTPS): Digunakan untuk mengakses halaman web secara aman.

Registered Ports (1024-49151) berisi daftar port ini IANA (Internet Assigned Numbers Authority) dan
dapat digunakan oleh aplikasi atau layanan tertentu.
Contohnya:
Port 3306 (MySQL): Digunakan oleh database MySQL.
Port 8080: Digunakan sebagai port alternatif untuk server web.
Dynamic/Private Ports (49152-65535): port-port ini digunakan untuk aplikasi yang tidak memiliki port
yang didedikasikan secara khusus. Port-port ini juga digunakan oleh klien untuk berkomunikasi dengan
server.
The two primary protocols at the transport layer are4:
Transmission Control Protocol (TCP), and
User Datagram Protocol (UDP).
TCP providing reliable, ordered, and error-checked delivery, whereas UDP support faster,
connectionless communication.
Other Transport Layer Protocols are (a) SCTP (Stream Control Transmission Protocol): Combines
features of both TCP and UDP, offering reliable and ordered data delivery with multiple streams, and
(b) DCCP (Datagram Congestion Control Protocol): A protocol designed to control congestion in
datagram-based networks.

Perbedaan TCP dan UDP

Contoh aplikasi yang menggunakan TCP ...


Contoh aplikasi yang menggunakan UDP ...
Contoh port yang menggunakan TCP ...
Contoh port yang menggunakan UDP ...

4 https://www.geeksforgeeks.org/transport-layer-protocols/
Tahapan komunikasi menggunakan socket

Bind = menetapkan alamat IP dan port


Listen = mengaktifkan & siap mendengar
Connect = menghubungi tujuan
Accept = menerima koneksi
Send/Receive = mengirim/menerima

Processes running on different machines communicate with each other by sending messages into
sockets. We said that each process was analogous to a house and the process's socket is analogous to a
door. As shown in Figure 21, the socket is the door between the application process and TCP. The
application developer has control of everything on the application-layer side of the socket; however, it
has little control of the transport-layer side.5

Figure 21: Processes communicating through TCP sockets.

Now let's to a little closer look at the interaction of the client and server programs. The client has the
job of initiating contact with the server. In order for the server to be able to react to the client's initial
contact, the server has to be ready. This implies two things.
First, the server program can not be dormant; it must be running as a process before the client attempts
to initiate contact.
Second, the server program must have some sort of door (i.e., socket) that welcomes some initial
contact from a client (running on an arbitrary machine). Using our house/door analogy for a
process/socket, we will sometimes refer to the client's initial contact as "knocking on the door".

With the server process running, the client process can initiate a TCP connection to the server. This is
done in the client program by creating a socket object. When the client creates its socket object, it
specifies the address of the server process, namely, the IP address of the server and the port number of
the process. Upon creation of the socket object, TCP in the client initiates a three-way handshake and
establishes a TCP connection with the server. The three-way handshake is completely transparent to
the client and server programs.
During the three-way handshake, the client process knocks on the welcoming door of the server
process. When the server "hears" the knocking, it creates a new door (i.e., a new socket) that is
dedicated to that particular client. In our example below, the welcoming door is a ServerSocket object
that we call the welcomeSocket. When a client knocks on this door, the program invokes
welcomeSocket's accept() method, which creates a new door for the client. At the end of the
handshaking phase, a TCP connection exists between the client's socket and the server's new socket.
Henceforth, we refer to the new socket as the server's "connection socket".
From the application's perspective, the TCP connection is a direct virtual pipe between the client's
socket and the server's connection socket. The client process can send arbitrary bytes into its socket;
TCP guarantees that the server process will receive (through the connection socket) each byte in the

5 http://www2.ic.uff.br/~michael/kr1999/2-application/2_06-sockettcp.htm
order sent. Furthermore, just as people can go in and out the same door, the client process can also
receive bytes from its socket and the server process can also send bytes into its connection socket. This
is illustrated in Figure 22.

Figure 22: Client socket, welcoming socket and connection socket.

Because sockets play a central role in client-server applications, client-server application


development is also referred to as socket programming. Before providing our example client-server
application, it is useful to discuss the notion of a stream. A stream is a flowing sequence of characters
that flow into or out of a process. Each stream is either an input stream for the process or an output
stream for the process. If the stream is an input stream, then it is attached to some input source for the
process, such as standard input (the keyboard) or a socket into which characters flow from the Internet.
If the stream is an output stream, then it is attached to some output source for the process, such as
standard output (the monitor) or a socket out of which characters flow into the Internet.

Buatlah iilustrasi yang menunjukkan tahapan terjadinya three-way handshake pada koneksi TCP antara
client – server !
Buatlah iilustrasi yang menunjukkan tidak terjadinya handshake pada koneksi UDP antara client –
server !

TUGAS
Jawablah pertanyaan (ada 7) yg diberi tanda warna kuning pada materi diatas!

Anda mungkin juga menyukai