Tugas 4 PAM1 – Multiclient-Emoticon Bluetooth Chat


‘ncen marai emosi kowe ki mas Wisnu!!!!
senengane nge’i tugas ‘ik ya… 😦 😦

Anda Punya Masalah Dengan Berat Badan (nggak nyindir Tiu* + Dew* kok 😛 :P)???

Anda Ingin Langsing tanpa Sedot lemak dan Fitness???

Anda Punya bakat Melek malam alias insomnia???

Anda Ingin menyalurkan bakat anda ini???

yak… Anda Tepat jika datang ke sini….

dijamin anda tak akan pernah menyesal

NO!!!

Klik Di Sini, Nggak Nyesel Dehhh..

 

Syarat-Syarat (KELAS RABU):

  • Bikinnya Kelompok kayak kemaren… (pas bikin peta)
  • Kumpulin besok SABTU, 23 Oktober 2010 JAM MALAM (Seperti Biasa… biar ga dilihat orang 😀 )
  • Ke yere.getlife@yahoo.com
  • SUBJECT dan FILE : UNTUBIRU_NIM1_NIM2
  • Tugas Sebagai Nilai Asisten Dan Nilai Dosen

Kalo agan-agan nggak ngerjain +nggak  ngumpulin berarti agan

maho DETECTED

 

mohon cendolnya gan….. Jangan di kasih Bata

 

 

Mari Kita Berbuat Untuk Negeri Tercinta Ini!!!

PET[m]UNJ[y]UK dari A’ak Marsel:

Server:


import java.io.InputStream;
import javax.bluetooth.DiscoveryAgent;
import javax.bluetooth.LocalDevice;
import javax.bluetooth.UUID;
import javax.microedition.io.Connector;
import javax.microedition.io.StreamConnection;
import javax.microedition.io.StreamConnectionNotifier;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.midlet.*;
/**
 * @author hardjodiningrat
 */
public class Server extends MIDlet implements CommandListener, Runnable {
    Form formUtama;
    Command start;
    String url = "";
    UUID REFCOMM_UUID = new UUID(5000);
    LocalDevice perangkat;
    StreamConnectionNotifier notif;
    StreamConnection con;
    InputStream is;
    public Server() {
        this.url = "btspp://localhost:" + this.REFCOMM_UUID + ";name=rfcommtest;authorize=true";
        this.formUtama = new Form("Form Server");
        this.start = new Command("Start", Command.OK, 0);
        this.formUtama.append("Form Server");
        this.formUtama.addCommand(start);
        this.formUtama.setCommandListener(this);
        Display.getDisplay(this).setCurrent(formUtama);
    }
    public void startApp() {
    }
    public void pauseApp() {
    }
    public void destroyApp(boolean unconditional) {
    }
    public void commandAction(Command c, Displayable d) {
        if (c == this.start) {
            new Thread(this).start();
        }
    }
    public void setDiscoveredOn() throws Exception {
        this.perangkat = LocalDevice.getLocalDevice();
        this.perangkat.setDiscoverable(DiscoveryAgent.GIAC);
    }
    public void openConnection() throws Exception {
        this.notif = (StreamConnectionNotifier) Connector.open(this.url);
        System.out.println("URL: " + this.url);
        this.formUtama.append("\nServer started. Waiting for client...");
        this.con = this.notif.acceptAndOpen();
        this.is = this.con.openInputStream();
        int c = 0;
        String data = "";
        while ((c = is.read()) != -1){
            if((char)c == '|'){
                this.formUtama.append(data);
                data = "";
            }else
                data += (char) c;
        }
    }
    public void run() {
        try {
            this.setDiscoveredOn();
            this.openConnection();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}

Client:

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import java.io.IOException;
import java.io.OutputStream;
import java.util.Vector;
import javax.bluetooth.BluetoothStateException;
import javax.bluetooth.DeviceClass;
import javax.bluetooth.DiscoveryAgent;
import javax.bluetooth.DiscoveryListener;
import javax.bluetooth.LocalDevice;
import javax.bluetooth.RemoteDevice;
import javax.bluetooth.ServiceRecord;
import javax.bluetooth.UUID;
import javax.microedition.io.Connector;
import javax.microedition.io.StreamConnection;
import javax.microedition.lcdui.Choice;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.List;
import javax.microedition.midlet.*;
/**
 * @author hardjodiningrat
 */
public class Client extends MIDlet implements CommandListener, DiscoveryListener{
    List listUtama;
    Command com;
    LocalDevice perangkat;
    DiscoveryAgent agent;
    DiscoveryAgent serv;
    Vector listPerangkat = new Vector();
    StreamConnection con;
    OutputStream os;
    String url = "";
    boolean ada = false;
    public Client() {
        this.listUtama = new List("List Perangkat", Choice.IMPLICIT);
        this.com = new Command("Kirim", Command.OK, 0);
        this.listUtama.setCommandListener(this);
        Display.getDisplay(this).setCurrent(listUtama);
        try {
            this.cariPerangkat();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public void startApp() {
    }
    public void pauseApp() {
    }
    public void destroyApp(boolean unconditional) {
    }
    public void deviceDiscovered(RemoteDevice btDevice, DeviceClass cod) {
        try {
            this.listPerangkat.addElement(btDevice);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    public void servicesDiscovered(int transID, ServiceRecord[] records) {
        for (int i = 0; i < records.length; i++) {
            this.url = records[i].getConnectionURL(ServiceRecord.AUTHENTICATE_ENCRYPT, false);
            System.out.println("URL: " + this.url);
            if(this.url.startsWith("btspp")){
                break;
            }
        }
    }
    public void serviceSearchCompleted(int transID, int respCode) {
        try {
            if(!this.ada){
                if(this.con != null) this.con.close();
                this.con = (StreamConnection) Connector.open(this.url);
                this.os = this.con.openOutputStream();
                this.ada = true;
                this.listUtama.addCommand(com);
            }
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
    public void inquiryCompleted(int discType) {
        try {
            RemoteDevice dev = null;
            for (int i = 0; i < this.listPerangkat.size(); i++) {
                dev = (RemoteDevice)this.listPerangkat.elementAt(i);
                this.listUtama.append(dev.getFriendlyName(true), null);
            }
        } catch (Exception e) {
        }
    }
    public void commandAction(Command c, Displayable d) {
        if(c == List.SELECT_COMMAND && !ada){
            try {
                RemoteDevice dev = (RemoteDevice) this.listPerangkat.elementAt(this.listUtama.getSelectedIndex());
                int searchId = this.agent.searchServices(null, new UUID[]{new UUID(5000)}, dev, this);
            } catch (BluetoothStateException ex) {
                ex.printStackTrace();
            }
        }
        if(c == this.com){
            if(this.ada){
                try {
                    this.os.write("yere busuk....|".getBytes());
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
            }
        }
    }
    public void cariPerangkat() throws Exception{
        this.perangkat = LocalDevice.getLocalDevice();
        this.agent = this.perangkat.getDiscoveryAgent();
        this.agent.startInquiry(DiscoveryAgent.GIAC, this);
    }
}

Salam Sayang,

Happy Source Code

Advertisements

One Response

  1. mau tanya..
    ko waktu saya compile dan saya jalankan…

    kenapa ada erorr
    Unable to create MIDlet bluetoothchatting
    java.lang.ClassNotFoundException: bluetoothchatting
    at com.sun.midp.midlet.MIDletState.createMIDlet(+29)
    at com.sun.midp.midlet.Selector.run(+22)

    ap ayang salah yach kira2?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: