Sebelumnya kita sudah tau cara kerja bluetooth, sekarang kita buat aplikasinya, yang ini, untuk servernya pake J2SE. mau tau listingnya?
package server; import java.io.IOException; import javax.bluetooth.BluetoothStateException; import javax.bluetooth.LocalDevice; import javax.bluetooth.ServiceRecord; import javax.microedition.io.Connector; import javax.microedition.io.StreamConnection; import javax.microedition.io.StreamConnectionNotifier; /** * * @author Dyah Fajar */ public class Test { public static void main (String [] args) { new Test().run(); } public void run() { StreamConnectionNotifier notifier; try { notifier = (StreamConnectionNotifier) Connector.open("btspp://localhost:123456789ABCDE;name=Echo Server"); displayConnectionString(notifier); // Continue accepting connections until the MIDlet is destroyed for (;;) { System.out.println("Try to Connect"); StreamConnection conn = notifier.acceptAndOpen(); System.out.println("Connected "); } } catch (IOException ex) { System.out.println("error"); } } private void displayConnectionString(StreamConnectionNotifier notifier) { try { // Retrieve the connection string to use to // connect to this server LocalDevice device = LocalDevice.getLocalDevice(); ServiceRecord record = device.getRecord(notifier); String connString = record.getConnectionURL(ServiceRecord.NOAUTHENTICATE_NOENCRYPT, false); int index = connString.indexOf(';'); connString = connString.substring(0, index); // Display the connection string on the Form System.out.println("Connection String:\n"); System.out.println(connString); System.out.println("\n"); } catch (BluetoothStateException e) { System.out.println("BluetoothStateException: " + e.getMessage()); } } } |
Ups, sampe lupa, jangan lupa untuk menambahkan library tambahan bluecove, supaya bisa memakai package bluetooth. Selamat mencoba..
kita juga punya nih artikel mengenai J2SE, berikut linknya semoga bermanfaat ya :D
BalasHapushttp://repository.gunadarma.ac.id/bitstream/123456789/2938/1/Artikel_10105421.pdf
kita juga punya nih artikel mengenai 'J2SE', silahkan dikunjungi dan dibaca , berikut linknya
BalasHapushttp://repository.gunadarma.ac.id/bitstream/123456789/5666/1/PPT%20korea.pdf
terimakasih