LAMPIRAN 1 Tutorial Implementasi Editor Pengukuran, Pengiriman dan Penerimaan a.
Implementasi Editor Pengukuran Berikut adalah langkah-langkah pengukuran meliputi: 1. Buka editor arduino kemudian setting sketch dan tools menggunakan arduino UNO. 2. Masukkan listing program sesuai dengan pengukuran yang diinginkan. 3. Kemudian lakukan verify load library setelah selesai upload dan serialkan kepada monitor tampilan data. 4. Catat hasil pengukuran.
b.
Implementasi Editor Pengiriman Menggunakan Wireless Tool Kit 2.5.2 Berikut adalah langkah-langkah menginstall editor pengiriman meliputi: 1. Siapkan editor Wireless Tool Kit 2.5.2 2. Edit listing program sesuai dengan protokol yang digunakan yaitu UDP dan TCP. 3. Lakukan perintah open project pada WTK kemudian setting sesuai dengan perangkat yang digunakan yaitu Nokia series E63. 4. Untuk mendapatkan file yang sudah dieksekusi dalam format .jar pilih perintah set package. 5. Setelah format .jar muncul pada folder WTK lakukan build project untuk menjalankan project yang sudah dibuat pada emulator yang sudah disediakan. 6. Ambil file eksekusi yang berformat .jar lalu install pada perangkat Nokia series E63. 7. Aplikasi akan muncul pada layar handphone dan siap untuk dilakukan proses pengiriman.
c.
Implementasi Editor Penerimaan Menggunakan Netbeans 8.0.1 Berikut adalah langkah-langkah menjalankan editor penerimaan meliputi: 1. Siapkan editor Netbeans 8.0.1 2. Edit listing program sesuai dengan protokol yang digunakan yaitu UDP dan TCP 3. Lakukan perintah open package pada editor Netbeans.
4. Setelah file muncul maka langkah selanjutnya adalah mensetting IP address dari perangkat pengirim. 5. Kemudian pilih perintah run file. 6. Setelah kedua perangkat terhubung, catat hasil pengiriman dan penerimaan.
LAMPIRAN 2 Listing Program Monitoring Pengukuran Menggunakan Arduino UNO #include <Time.h> int voltPin = 0; //voltage divider (middle terminal) connected to analog pin 0 int currentPin = 2; //TMP36 data pin int val = 0; // variable to store the value read int volt = 0; //variable to store the voltage calculated int current = 0; static const int RXPin = 19,TXPin = 18; void setup() { Serial.begin(9600); //setup serial setTime(9,20,0,17,01,15); // set time to noon August 8 2014 harus diset setiap melakukan uji coba } void loop() { int reading = analogRead(voltPin); //read the input pin float voltage = reading*4.2; voltage /= 1024.0; int reading2 = analogRead(currentPin); //read the input pin float current = voltage - reading2*4.2; current /= 1024.0; float v_negatif = voltage + current; Serial.print(voltage); Serial.print(" volts titik + "); Serial.print(v_negatif); Serial.print(" volts titik - "); float arus = current/0.22; Serial.print(arus); Serial.print(" ampere "); float power = (arus*arus*0.22)*1000; Serial.print(power); Serial.print(" milliwatt "); float energi = (power*3600)/1000; Serial.print(energi); Serial.print(" joule "); digitalClockDisplay(); delay(500); } void digitalClockDisplay(){ // digital clock display of the time Serial.print(hour()); printDigits(minute()); printDigits(second()); Serial.print(" ");
Serial.print(day()); Serial.print(" "); Serial.print(month()); Serial.print(" "); Serial.print(year()); Serial.println(); } void printDigits(int digits){ // utility function for clock colon and leading 0 Serial.print(":"); if(digits < 10) Serial.print('0'); Serial.print(digits); }
display:
prints
preceding
LAMPIRAN 3 Listing Program Pengirim Data Transmisi UDP dan TCP Menggunakan Bahasa Java Editor Wireless Tool Kit (WTK) 2.5.2 a. Pengirim Data Transmisi UDP import import import import import import import import import import import import import import import
java.io.IOException; java.util.Calendar; java.util.Date; javax.microedition.io.*; javax.microedition.io.Datagram; javax.microedition.io.DatagramConnection; javax.microedition.lcdui.Alert; javax.microedition.lcdui.AlertType; javax.microedition.lcdui.Command; javax.microedition.lcdui.CommandListener; javax.microedition.lcdui.Display; javax.microedition.lcdui.Displayable; javax.microedition.lcdui.Form; javax.microedition.lcdui.StringItem; javax.microedition.lcdui.TextField;
public class UDP implements Runnable, CommandListener { private DatagramMIDlet parent; private Display display; private Form f; private StringItem si; private TextField tf; private Command Command.ITEM, 1);
startCommand
=
private Command Command.EXIT, 1);
exitCommand
=
new
new
Command("Start",
Command("Exit",
private String address; String portString=null; private int port; Datagram dg=null; DatagramConnection dc=null; int [] dataVideo = {27905,10857,10917,10515,11907,11781,9177,12155,11000,12108, 12302,11632,12925,13483,14148,13980,13712,13552,13047,12577, 12444,9233,11987,11228,12680,12126,12303,7804,9186,8085,3124 0,11651,12027,10740,10423,11018,11248,11677,11357,11753,9010 ,9752,10805,10338,11190,10750,10708,12489,12904,12950,11123, 10705,10616,8986,14107,13506,11235,11216,12941,10818,31106,1 2476,11951,12363,11544,11067,11534,11980,11709,10765,11147,1 0873,10970,11726,11119,10775,11780,12343,13098,12615,12790,1
0794,11144,12698,13855,13137,12396,10971,12085,13142,29278,1 2874,13496,13151,12708,12505,10515,9982,10110,9883,9687,1064 1,10899,10513,9948,9885,10573,7807,10218,11314,10749,11022,1 1133,10697,10294,11288,11115,8114,9364,10308,28494,8786,1124 9,11913,11774,12409,13288,12369,11681,11319,11402,10929,1204 3,12540,13292,13490,13149,13797,13858,14737,14607,14331,1456 4,12183,13580,11448,10271,10285,11285,9210,26459,10331,11038 ,14130,15156,13330,14587,14574,14217,12256,11247,9761,10684, 10049,11178,10881,10122,10911,11036,11254,12558,13251,13286, 13264,13276,12107,12418,12088,11178,11337,24525,9651,10029,1 0542,10987,10391,10336,9674,8960,10312,10262,10967,10846,107 58,10961,12361,12516,10760,10072,9608,9883,10452,10218,9691, 9403,9326,9421,8636,9578,9950,23711,11427,12099,11643,11177, 11786,12914,15258,16807,18862,19315,18799,19767,15869,15771, 13366,14238,13196,17803,20947,20938,20302,21273,23927,22763, 21242,22183,19795,23711,18951,43787,20868,21750,21976,24037, 24528,24831,24249,21167,20932,20143,24477,16516,20241,22495, 25438,25269,26435,17921,19784,24119,26064,26342,21836,17681, 20602,22030,22848,23277,22502,45781,14661,19359,18430,16623, 18240,14352,17137,18796,18626,16799,15646,21259,22197,18583, 22628,25014,23053,21356,21428,22351,21949,19129,16436,21768, 25520,24413,24244,21886,17520}; //Generate byte 010101; String s ="0100000101000001010000010100000101000001010000010100000101 000001010000010100000101000001010000010100000101000001010000 010100000101000001010000010100000101000001010000010100000101 000001010000010100000101000001010000010100000101000001010000 010100000101000001010000010100000101000001010000010100000101 000001010000010100000101000001010000010100000101000001010000 010100000101000001010000010100000101000001010000010100000101 000001" + "01000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 10100000101000001010000010100000101000001" + "01000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 10100000101000001010000010100000101000001" + "01000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000
101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 10100000101000001010000010100000101000001" + "01000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 10100000101000001010000010100000101000001" + "01000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 10100000101000001010000010100000101000001" + "01000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 10100000101000001010000010100000101000001" + "01000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 10100000101000001010000010100000101000001" + "01000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 10100000101000001010000010100000101000001" + "01000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 10100000101000001010000010100000101000001" + "01000001010000010100000101000001010000010100000101000001010
000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 10100000101000001010000010100000101000001" + "01000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 10100000101000001010000010100000101000001" + "01000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 10100000101000001010000010100000101000001" + "01000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 10100000101000001010000010100000101000001" + "01000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 10100000101000001010000010100000101000001" + "01000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 10100000101000001010000010100000101000001" + "01000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010
000010100000101000001010000010100000101000001010000010100000 10100000101000001010000010100000101000001" + "01000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 10100000101000001010000010100000101000001" + "01000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 10100000101000001010000010100000101000001" + "01000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 10100000101000001010000010100000101000001" + "01000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 10100000101000001010000010100000101000001" + "01000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 10100000101000001010000010100000101000001"; int urutan =0; byte[] bytes = null; public UDP(DatagramMIDlet m, int p) { parent = m; port = p; display = Display.getDisplay(parent); f = new Form("UDP Server"); si = new StringItem("Status:", " "); f.append(si); //f.addCommand(startCommand);
f.addCommand(exitCommand); f.setCommandListener(this); display.setCurrent(f); portString = String.valueOf(port); } public void start() { Thread t = new Thread(this); t.start(); } public void run() { try { si.setText("Menunggu permintaan sambungan "+portString); dc = (DatagramConnection) Connector .open("datagram://:" + portString); while (true) { dg = dc.newDatagram(100); dc.receive(dg); address = dg.getAddress(); si.setText("Permintaan diterima " + new String(dg.getData(), 0, dg.getLength())); //Program mengirim video //Kirim video 6x10detik for(int k=0;k<6;k++){ int frame=dataVideo.length; for(int i=0;i
Thread.currentThread().interrupt(); } urutan++; } } } } catch (IOException ioe) { Alert a = new Alert("Server", "Port " + portString + " is already taken.", null, AlertType.ERROR); a.setTimeout(Alert.FOREVER); a.setCommandListener(this); display.setCurrent(a); } catch (Exception e) { e.printStackTrace(); } } public void commandAction(Command c, Displayable s) { if ((c == Alert.DISMISS_COMMAND) exitCommand)) { parent.destroyApp(true); parent.notifyDestroyed(); } } public void stop() { } }
||
(c
==
b. Pengirim Data Transmisi TCP import import import import import import import import import import import import import import import import import
java.util.Calendar; java.util.Date; java.io.IOException; java.io.InputStream; java.io.OutputStream; javax.microedition.io.*; javax.microedition.io.Connector; javax.microedition.io.SocketConnection; javax.microedition.lcdui.Alert; javax.microedition.lcdui.AlertType; javax.microedition.lcdui.Command; javax.microedition.lcdui.CommandListener; javax.microedition.lcdui.Display; javax.microedition.lcdui.Displayable; javax.microedition.lcdui.Form; javax.microedition.lcdui.StringItem; javax.microedition.lcdui.TextField;
public class TCP implements Runnable, CommandListener { private DatagramMIDlet parent; private Display display; private Form f; private StringItem si; private TextField tf; private Command Command.ITEM, 1);
startCommand
=
private Command Command.EXIT, 1);
exitCommand
=
new
new
Command("Start",
Command("Exit",
private String address; String portString=null; InputStream is; private int port; OutputStream os; SocketConnection sc; ServerSocketConnection scn; int [] dataVideo = {27905,10857,10917,10515,11907,11781,9177,12155,11000,12108,
12302,11632,12925,13483,14148,13980,13712,13552,13047,12577, 12444,9233,11987,11228,12680,12126,12303,7804,9186,8085,3124 0,11651,12027,10740,10423,11018,11248,11677,11357,11753,9010 ,9752,10805,10338,11190,10750,10708,12489,12904,12950,11123, 10705,10616,8986,14107,13506,11235,11216,12941,10818,31106,1 2476,11951,12363,11544,11067,11534,11980,11709,10765,11147,1 0873,10970,11726,11119,10775,11780,12343,13098,12615,12790,1 0794,11144,12698,13855,13137,12396,10971,12085,13142,29278,1 2874,13496,13151,12708,12505,10515,9982,10110,9883,9687,1064 1,10899,10513,9948,9885,10573,7807,10218,11314,10749,11022,1 1133,10697,10294,11288,11115,8114,9364,10308,28494,8786,1124 9,11913,11774,12409,13288,12369,11681,11319,11402,10929,1204 3,12540,13292,13490,13149,13797,13858,14737,14607,14331,1456 4,12183,13580,11448,10271,10285,11285,9210,26459,10331,11038 ,14130,15156,13330,14587,14574,14217,12256,11247,9761,10684, 10049,11178,10881,10122,10911,11036,11254,12558,13251,13286, 13264,13276,12107,12418,12088,11178,11337,24525,9651,10029,1 0542,10987,10391,10336,9674,8960,10312,10262,10967,10846,107 58,10961,12361,12516,10760,10072,9608,9883,10452,10218,9691, 9403,9326,9421,8636,9578,9950,23711,11427,12099,11643,11177, 11786,12914,15258,16807,18862,19315,18799,19767,15869,15771, 13366,14238,13196,17803,20947,20938,20302,21273,23927,22763, 21242,22183,19795,23711,18951,43787,20868,21750,21976,24037, 24528,24831,24249,21167,20932,20143,24477,16516,20241,22495, 25438,25269,26435,17921,19784,24119,26064,26342,21836,17681, 20602,22030,22848,23277,22502,45781,14661,19359,18430,16623, 18240,14352,17137,18796,18626,16799,15646,21259,22197,18583, 22628,25014,23053,21356,21428,22351,21949,19129,16436,21768, 25520,24413,24244,21886,17520}; //Generate byte 010101; String s ="0100000101000001010000010100000101000001010000010100000101 000001010000010100000101000001010000010100000101000001010000 010100000101000001010000010100000101000001010000010100000101 000001010000010100000101000001010000010100000101000001010000 010100000101000001010000010100000101000001010000010100000101 000001010000010100000101000001010000010100000101000001010000 010100000101000001010000010100000101000001010000010100000101 000001" + "01000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 10100000101000001010000010100000101000001" + "01000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010
000010100000101000001010000010100000101000001010000010100000 10100000101000001010000010100000101000001" + "01000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 10100000101000001010000010100000101000001" + "01000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 10100000101000001010000010100000101000001" + "01000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 10100000101000001010000010100000101000001" + "01000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 10100000101000001010000010100000101000001" + "01000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 10100000101000001010000010100000101000001" + "01000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 10100000101000001010000010100000101000001" + "01000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000
101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 10100000101000001010000010100000101000001" + "01000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 10100000101000001010000010100000101000001" + "01000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 10100000101000001010000010100000101000001" + "01000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 10100000101000001010000010100000101000001" + "01000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 10100000101000001010000010100000101000001" + "01000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 10100000101000001010000010100000101000001" + "01000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 10100000101000001010000010100000101000001"
+ "01000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 10100000101000001010000010100000101000001" + "01000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 101000001010000010100000101000001010000010100000101000001010 000010100000101000001010000010100000101000001010000010100000 10100000101000001010000010100000101000001"; int urutan =0; byte[] bytes = null; public TCP(DatagramMIDlet m, int p) { parent = m; port = p; display = Display.getDisplay(parent); f = new Form("TCP Server"); si = new StringItem("Status:", " "); f.append(si); //f.addCommand(startCommand); f.addCommand(exitCommand); f.setCommandListener(this); display.setCurrent(f); portString = String.valueOf(port); } public void start() { Thread t = new Thread(this); t.start(); } public void run() { try { si.setText("Menunggu "+portString); scn = Connector.open("socket://:" + portString);
permintaan
sambungan
(ServerSocketConnection)
// Wait for a connection. sc = (SocketConnection) scn.acceptAndOpen(); si.setText("Permintaan diterima "); is = sc.openInputStream(); os = sc.openOutputStream(); boolean sending =false;
boolean rec =true; StringBuffer sb = new StringBuffer(); while (rec) { int c = 0; c = is.read(); if(c==10){ sending=true; rec=false; si.setText("Message
received
-
"
+
sb.toString()); } } while (sending) { //Program mengirim video int frame=dataVideo.length; for(int k=0;k<6;k++){ for(int i=0;i
paket
"+urutan+" frame:"+i); } catch (Exception ioe) { ioe.printStackTrace(); } urutan++; } try { Thread.sleep(30);//1000 milliseconds is one second. } catch(InterruptedException ex) { Thread.currentThread().interrupt(); } urutan++;
} } sending=false; } } catch (IOException ioe) { if (ioe.getMessage().equals("ServerSocket Open")) { Alert a = new Alert("Server", "Port " + portString + " is already taken.", null, AlertType.ERROR); a.setTimeout(Alert.FOREVER); a.setCommandListener(this); display.setCurrent(a); } else { ioe.printStackTrace(); } } catch (Exception e) { e.printStackTrace(); } } public void commandAction(Command c, Displayable s) { if ((c == Alert.DISMISS_COMMAND) exitCommand)) { parent.destroyApp(true); parent.notifyDestroyed(); } } public void stop() { } }
||
(c
==
LAMPIRAN 4 Listing Program Penerima Data Transmisi UDP dan TCP Menggunakan Bahasa Java Editor Netbeans 8.0.1 a. Penerima Data Transmisi UDP import java.io.*; import java.net.*; import java.util.*; class UDPClient { private InetAddress IPAddress; boolean done; //boolean keepGoing; public UDPClient(String sHostName) { String s1; int size; BufferedReader br; try { IPAddress = InetAddress.getByName(sHostName); System.out.println ("Attemping to connect to IPAddress + ") via UDP port 5555"); } catch (UnknownHostException ex) { System.err.println(ex); System.exit(1); }
"
+
// set up the buffered reader to read from the keyboard try { DatagramSocket clientSocket = new DatagramSocket(); byte[] sendData = new byte[1024]; s1 = "Request"; sendData = s1.getBytes(); System.out.println ("Sending data to " + sendData.length); DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, 5555); clientSocket.send(sendPacket); byte[] receiveData = new byte[1024]; DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length); System.out.println ("Waiting for return packet");
//clientSocket.setSoTimeout(100000000); while (true){ Date date = new Date(); try { clientSocket.receive(receivePacket); System.out.println("Terima :"+date.getTime()+" "+receivePacket.getLength()+" "+new String(receivePacket.getData())); } catch (SocketTimeoutException ste){ System.out.println ("Timeout Occurred: Packet assumed lost"); // if (done) // keepGoing = false; } System.out.println(); } clientSocket.close();
//
} catch (IOException ex) { System.err.println(ex); } }
public static void main(String args[]) throws Exception { String serverHostname = new String ("192.168.101.11"); if (args.length > 0) serverHostname = args[0]; new UDPClient (serverHostname); } }
b. Penerima Data Transmisi TCP import java.io.*; import java.net.*; import java.util.Date; class TCPClient { public static void main(String argv[]) throws Exception { String sentence; String modifiedSentence; BufferedReader inFromUser = new BufferedReader( new InputStreamReader(System.in)); Socket clientSocket = new Socket("192.168.101.11", 5555); DataOutputStream outToServer = new DataOutputStream( clientSocket.getOutputStream()); DataInputStream inServer = new DataInputStream(clientSocket.getInputStream()); BufferedReader inFromServer = new BufferedReader(new InputStreamReader( clientSocket.getInputStream())); sentence = "1"; outToServer.write(10); byte[] a=null; while(true){ Date date = new Date(); modifiedSentence = inServer.readUTF(); System.out.println("Terima : "+date.getTime()+" "); System.out.println(modifiedSentence); //System.out.println('\n'); }
} //clientSocket.close(); }