السلام عليكم ورحمة الله....
ارجو من اعضاء هذا المنتدى المتميز مساعدتي في مشروع التخرج...
الفكرة المشروع هي الربط بين الجوال-الزبون- والكمبيوتر-الخادم-باستخدام البلوتوث ولكن لدي عدة استفسارات:
الاستفسار الأول هو هل من الأفضل استخدام L2CAP protocol أم RFCOMM ام علي استخدام الاثنين معا، لانني قرأت ان L2CAP اسرع لانه يعتمد على نقل packetوليس stream
فانا احتاج نقل كمية قليلة بحيث لا تتجاوز سطرين ولكن احتاج السرعة لان العملية ستتم داخل القاعات الدراسية...
المشكلة الثانية هي انه عند البحث عن اجهزة البلوتوث المجاورة باستخدام الجوال تظهر جميع اجهزة البلوتوث المجاورة...كيف احصل على
connection string
الخاص بالسيرفر الذي اخترته قبل ان يكون هناك كائن من نوع
stream connection
لان الConnector.open لا تعمل الا بادخال الconnection string ...
لاني اريد الطالب يرتبط بالكمبيوتر الشخصي للاستاذ دون ادخال اي شيء فقط يختاره...
حاولت عمل هذه الطريقة:
client code:
import java.io.*;
import javax.microedition.io.*;
import javax.bluetooth.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class client extends MIDlet implements
Runnable, CommandListener{
private Display display;
private Form form;
private DiscoveryAgent agent;
private Command exitCommand;
private Command searchCommand;
private Command connect;
private Command Back;
private List deviceList;
private boolean found=false;
private Alert alert; //radio button alert
private String conString;
private int size;
public void run() {
form = new Form("Client");
form.append("Welcome to the client..\n");
//form.append("searching..\n");
display = Display.getDisplay(this);
display.setCurrent(form);
exitCommand = new Command("Exit", Command.EXIT, 1);
searchCommand = new Command("Search",
Command.SCREEN, 1);
form.addCommand(exitCommand);
form.addCommand(searchCommand);
form.setCommandListener(this);
}
public void BluetoothMIDlet() {}
public void startApp()
throws MIDletStateChangeException {
new Thread(this).start();
}
public void pauseApp() {}
public void destroyApp(boolean unconditional) {}
public void commandAction(Command c, Displayable d) {
if (c==searchCommand)
try {
search();
} catch (BluetoothStateException ex) {
ex.printStackTrace();
} catch (MIDletStateChangeException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}
else if(c== connect)
try {
connect();
} catch (BluetoothStateException ex) {
ex.printStackTrace();
}
else if(c==Back){
}
else
notifyDestroyed();
}
public void search() throws BluetoothStateException, MIDletStateChangeException, IOException{
LocalDevice local = LocalDevice.getLocalDevice();
agent=local.getDiscoveryAgent();
// Prevent the application from starting if the
// Bluetooth device
// could not be retrieved.
deviceList = new List("List of Servers:", List.IMPLICIT);
deviceList.addCommand(new Command("connect",
Command.OK, 1));
deviceList.addCommand(new Command("Back",
Command.BACK, 1));
deviceList.setCommandListener(this);
Display.getDisplay(this).setCurrent(deviceList);
alert = new Alert("Connection Successful :) ",
deviceList.getString(deviceList.getSelectedIndex()),
null, null);
alert.setTimeout(Alert.FOREVER);
alert.setType(AlertType.INFO);
display.setCurrent(alert);
deviceList.removeCommand(connect);
addDevices_preKnown();
if(!found)
addDevices_cached();
}
public void connect() throws BluetoothStateException{
try {
StreamConnection conn = (StreamConnection)
Connector.open(conString);
OutputStream out = conn.openOutputStream();
out.write("Trying to establish Bluetooth connection...".getBytes());
out.close();
conn.close();
form.append("Bluetooth connection successfully established.\n");
} catch(IOException e) {
form.append("IOException");
form.append(e.getMessage());
}
}
public void addDevices_preKnown() throws IOException {
RemoteDevice[] plist = agent.retrieveDevices(DiscoveryAgent.PREKNOWN);
size=plist.length;
if (plist != null) {
for (int i = 0; i <size; i++){
deviceList.append(plist.getFriendlyName(true),null);
if(deviceList.getSelectedIndex()==i){
sendAdd(plist.getBluetoothAddress());//try to get connection string and set its value to conString
connect();
found=true;
}
}
}
}
// Retrieve the cached device array and add the
// addresses to the
// list.
public void addDevices_cached() throws IOException {
RemoteDevice[] clist = agent.retrieveDevices(DiscoveryAgent.PREKNOWN);
if (clist != null) {
for (int i = 0; i <clist.length+size; i++){
deviceList.append(clist.getFriendlyName(true),null);
if(deviceList.getSelectedIndex()==i){
sendAdd(clist.getBluetoothAddress());//try to get connection string and set its value to conString
connect();
}
}
}
}
private void sendAdd(String bluetoothAddress) {
// Create the connection string
StringBuffer temp = new StringBuffer("btspp://");
temp.append(bluetoothAddress);
temp.append(":");
temp.append("2");
conString= temp.toString();
}
}
المشكلة الاخيرة هي انني عندما ابحث عن اجهزة البلوتوث القريبة اريد البحث عن اجهزة الكمبيوتر فقط وليس الجوالات الاخرى’ قرات ان هناك ما يسمى ب
device class
ولكن لم اعرف كيف استخدمه...
ارجوكم ساعدوني باسرع وقت ...
مع جزيل الشكر :)