Advanced Socket Programming

Slides:



Advertisements
Presentasi serupa
PEMOGRAMAN BERBASIS JARINGAN
Advertisements

Pemrograman Jaringan Socket Programming Aurelio Rahmadian.
OBJECT ORIENTED PROGRAMMING
Function.
Pemrograman Internet Mobile 7 PHP: Hypertext Preprocessors.
2. Introduction to Algorithm and Programming
I/O Stream lanjutan.
Learning Medium School : SMPN 1 Gotham City Subject : English
Lecture 5 Nonblocking I/O and Multiplexing Erick Pranata © Sekolah Tinggi Teknik Surabaya 1.
Network Programming Oleh: Idris Winarno.
GRADE/ SEMESTER : VII/ I
Zulharman. Tujuan Belajar 1. Mahasiswa mampu memahami berbagai metode membuat catatan kuliah (note taking) 2. Mahasiswa mampu memahami metode membaca.
Menulis Kolom  Kolom adalah opini atau artikel. Tidak seperti editorial, kolom memiliki byline.  Kolom Biasanya ditulis reguler. Biasanya mingguan atau.
1 Pertemuan 09 Kebutuhan Sistem Matakuliah: T0234 / Sistem Informasi Geografis Tahun: 2005 Versi: 01/revisi 1.
The development of the software in this context is parallel processing or known as parallelization. In this parallel processing this software used.
Collaboration Diagram State Diagram
PERTEMUAN KE-6 UNIFIED MODELLING LANGUAGE (UML) (Part 2)
1 Pertemuan 23 Sequence Diagram Matakuliah: M0086/Analisis dan Perancangan Sistem Informasi Tahun: 2005 Versi: 5.
Bayu Priyambadha, S.Kom.  Classes, which are the "blueprints" for an object and are the actual code that defines the properties and methods.  Objects,
HOW TO ACHIEVE 30% BLENDED LEARNING IN 1 HOUR. Objective To achieve 30% blended learning To achieve 30% blended learning.
9.3 Geometric Sequences and Series. Objective To find specified terms and the common ratio in a geometric sequence. To find the partial sum of a geometric.
-Do you have a close friend? Does she/he have a problem? -What do you say when she/he tells her/his problem? - Did you ever come to your friend house?
IP Addressing Laboratorium Teknik Informatika Universitas Gunadarma Stefanus Vlado Adi Kristanto Version 1.4.
Jartel, Sukiswo Sukiswo
ILIMA FITRI AZMI TEACHING MATERIAL DEVELOPMENT
Enkapsulasi.
AJAX (Asynchronous Javascript And XML)
KOMUNIKASI DATA Materi Pertemuan 3.
Induksi Matematika.
Pertemuan 23 Sequence Diagram
Notasi Object Oriented System
AJAX Teguh S.
Rekayasa Perangkat Lunak Class Diagram
Relationship Between Classes
CLASS DIAGRAM.
CA113 Pengantar Manajemen Bisnis
Pemrograman Berorientasi Objek
Algorithms and Programming Searching
Pemrograman Dasar TinyOS Menggunakan nesC
VLAN Virtual LAN.
JAva Threads.
CA113 Pengantar Manajemen Bisnis
Pertemuan 4 CLASS DIAGRAM.
How to Set Up AT&T on MS Outlook ATT is a multinational company headquartered in Texas. ATT services are used by many people widely across.
How You Can Make Your Fleet Insurance London Claims Letter.
How Can I Be A Driver of The Month as I Am Working for Uber?
How to Pitch an Event
Grow Your Social Media Communities
CA113 Pengantar Manajemen Bisnis
Algoritma & Pemrograman 1 Achmad Fitro The Power of PowerPoint – thepopp.com Chapter 4.
Lesson 2-1 Conditional Statements 1 Lesson 2-1 Conditional Statements.
V ERIZON SETTINGS FOR I P HONE, A NDROID, O UTLOOK, AND W INDOWS P HONE.
HughesNet was founded in 1971 and it is headquartered in Germantown, Maryland. It is a provider of satellite-based communications services. Hughesnet.
Do you want to check your Zoho mail incoming or outgoing logs and unable to check, go through with this article and access Zoho mail incoming or outgoing.
 Zoho Mail offers easy options to migrate data from G Suite or Gmail accounts. All s, contacts, and calendar or other important data can be imported.
Fix problems opening Norton  Fix problems opening Norton This problem can happen after you update Norton. To fix the matter, restart the computer. Fix.
If you are an user, then you know how spam affects your account. In this article, we tell you how you can control spam’s in your ZOHO.
How do I Add or Remove a delegate to my Gmail account? Google launched delegation service 9 years ago for Gmail that allows you to give permission to access.
In this article, you can learn about how to synchronize AOL Mail with third-party applications like Gmail, Outlook, and Window Live Mail, Thunderbird.
Right, indonesia is a wonderful country who rich in power energy not only in term of number but also diversity. Energy needs in indonesia are increasingly.
Pemrograman berorientasi objek
Website: Website Technologies.
Rank Your Ideas The next step is to rank and compare your three high- potential ideas. Rank each one on the three qualities of feasibility, persuasion,
Vector. A VECTOR can describe anything that has both MAGNITUDE and DIRECTION The MAGNITUDE describes the size of the vector. The DIRECTION tells you where.
"More Than Words" Saying I love you, Is not the words, I want to hear from you, It's not that I want you, Not to say but if you only knew, How easy, it.
Draw a picture that shows where the knife, fork, spoon, and napkin are placed in a table setting.
2. Discussion TASK 1. WORK IN PAIRS Ask your partner. Then, in turn your friend asks you A. what kinds of product are there? B. why do people want to.
CLASS VS OBJECT INTRODUCTION OF CLASS. keyword class diikuti dengan nama class yang kita inginkan. Lebih baik digunakan kata yang diawali huruf.
HOW TO IMPROVE YOUR PUBLIC SPEAKING SKILLS. 2 3 INIKAH YANG SERING ANDA ALAMI SAAT PRESENTASI?
Wednesday/ September,  There are lots of problems with trade ◦ There may be some ways that some governments can make things better by intervening.
Transcript presentasi:

Advanced Socket Programming Yuliana Setiowati Politeknik Elektronika Negeri Surabaya PENS-ITS

Topik Memberikan gambaran singkat tentang object serialization Menunjukkan cara kerja dengan object serialization Menggambarkan cara kerja dengan obyek yang sudah ada dan objek yang dibuat sendiri Menunjukkan bagaimana untuk mengirim objek melalui socket Memberikan contoh multi-threaded server PENS-ITS

Object Serialization Object Serialization adalah suatu mekanisme dalam program untuk menyimpan state object ke sebuah file dan selanjutnya membaca kembali object tersebut untuk mengubah state object tsb atau mengirim object melalui jaringan menggunakan socket. Class yang diserialisasi dapat dilakukan dengan membuat class yang mengimplementasikan interface java.io.Serializable. Interface ini tidak mempunyai fungsi yang harus diimplementasikan, hanya sebagai interface penanda saja (a maker interface). Interface ini digunakan untuk memberi informasi ke Java virtual machine (JVM) bahwa object ini diserialisasi. PENS-ITS

Object Serialization Ada dua class utama yang digunakan untuk membaca dan menulis objek untuk stream yaitu ObjectOutputStream dan ObjectInputStream. ObjectOutputStream menyediakan fungsi writeObject untuk menulis sebuah objek ke output stream ObjectInputStream menyediakan fungsi readObject untuk membaca objek dari input stream. Penting !!! Bahwa objek yang digunakan dengan fungsi ini harus diserialisasikan. Artinya, class harus mengimplementasikan interface Serializable. PENS-ITS

Serializing Existing Classes Sekarang kita lihat bagaimana cara membaca / menulis obyek, atau object dari class yang tersedia, yang sudah mengimplementasikan interface Serializable. Class Date dapat diserialisasikan, artinya class ini telah mengimplementasikan interface Serializable. PENS-ITS

Serializing Existing Classes Membaca serialized object dan mencetak informasi object tsb. PENS-ITS

Serializing Existing Classes Untuk mengetahui apakah sebuah class adalah serializable, gunakan tool serialver yang terdapat di JDK. Menggunakan GUI PENS-ITS

Serializing Existing Classes shows that the Socket class is not serializable. PENS-ITS

Serializing Custom Classes how to serialize a custom class. In this example, we create a custom class, UserInfo PENS-ITS

Serializing Custom Classes The next step is to create a class that creates a instance of the UserInfo class and writes the object to an output stream as shown in Code Sample 4. The output stream in this example is a file called "name.out". The important thing to note from Code Sample 4 is that the writeObject method can be called any number of times to write any number of objects to the output stream. PENS-ITS

Serializing Custom Classes Finally, we write a class that reads the objects that have been saved, and invokes a method as shown in Code Sample 5. Again, as with writeObject, the readObject method can be called any number of times to read any number of objects from the input stream. PENS-ITS

Serializing Custom Classes To try out this example, compile the source files: UserInfo.java, SaveInfo.java, and ReadInfo.java. Run SaveInfo, then ReadInfo, and you would see some output similar to this: PENS-ITS

Transporting Objects over Sockets Now that we have seen how to write and read objects to/from I/O streams in a single process, let's see how to transport objects over sockets. First, we will see how to transport existing object (such as the Date object), then we will see how to transport custom objects. PENS-ITS

Transporting an existing object Here we develop a multi-threaded DateServer that listens on port 3000 and waits for requests from clients. Whenever there is a request, the server replies by sending a Date object (over sockets) to the client as shown in Code Sample 6. D4 PENS-ITS

PENS-ITS

Transporting an existing object Note: the DateServer is a multi-threaded server that is implemented by inheriting from the Thread class. Another approach to developing multi-threaded servers is to implement the Runnable interface instead (inheritance vs. composition). PENS-ITS

Transporting an existing object The client, DateClient, does not have to send any messages to the DateServer once a connection has been established. It simply receives a Date object that represents the current day and time of the remote machine. The client receives the object and prints the date as shown in Code Sample 7. PENS-ITS

Transporting an existing object PENS-ITS

Transporting Custom Objects In the previous example, we have worked with existing objects. What if you want to transport your own custom objects. Is the process different? In this example, we write an array multiplier server. The client sends two objects, each representing an array; the server receives the objects, unpack them by invoking a method and multiplies the arrays together and sends the output array (as an object) to the client. The client unpacks the array by invoking a method and prints the new array. We start by making the class, whose objects will be transportable over sockets, serializable by implementing the Serializable interface as shown in Code Sample 8. PENS-ITS

Transporting Custom Objects PENS-ITS

Transporting Custom Objects The next step is to develop the client. In this example, the client creates two instances of SerializedObject and writes them to the output stream (to the server), as shown from the source code in Code Sample 9. PENS-ITS

Transporting Custom Objects PENS-ITS

Transporting Custom Objects Now we need to develop the server, ArrayMultiplier. This server is similar to Code Sample 6. The only difference is in the processing. In this example, the server receives two objects, unpacks them and then multiplies the arrays together and finally sends the output as an object to the client. The ArrayMultiplier is shown in Code Sample 10. PENS-ITS

Transporting Custom Objects D4 PENS-ITS

Transporting Custom Objects PENS-ITS

PENS-ITS

Transporting Custom Objects To run this example, modify the ArrayClient source specifying the machine name or IP address where the ArrayMultiplier server will run. Note that if you wish to run the server and client of this particular example on two different machines then both machines must have a copy of the SerializedObject class. This breaks information hiding and force tight coupling. A solution to this problem would be to write an interface that extends the Serializable interface and then have the SerializedObject class in Code Sample 8 implement the new interface. Using this technique, you only need to provide copies of the interface to the client and server, but not implementation. If you run the ArrayMultiplier and ArrayClient successfully, you should get the output: The new array is: 15 15 15 15 15 15 15 PENS-ITS