Home Help Search Login Register


J2meForums  |  General Category  |  Programming (Moderators: mikkom, shendley)  |  Topic: bluetooth client/server « previous next »
Pages: [1] Print
Author

bluetooth client/server

 (Read 110 times)
itziksaban
New user
*
Posts: 12



View Profile
bluetooth client/server
« on: July 27, 2010, 09:35:52 am »

Hi guys,
I am writing a bluetooth client/server j2me application. However, when the client is nokia e71, the DiscoveryAgent.searchServices does not seem to work since servicesDiscovered isn't beeing called.

here is the server code:
Code:
            StreamConnectionNotifier notifier = null;
            StreamConnection con = null;
            LocalDevice localdevice = null;
            ServiceRecord servicerecord = null;
            InputStream input;
            String url = "btspp://localhost:63236351871240528A8EA94C3ABF2B7D;name=serialconn";

            notifier = (StreamConnectionNotifier) Connector.open(url);
            con = notifier.acceptAndOpen();
            input = con.openInputStream();
            byte[] b = new byte[100];
            input.read(b);
            String s = new String(b);
            stringItem.setText(s);

here is the client code:
Code:
public class BTClient extends MIDlet implements DiscoveryListener {

    StringItem stringItem = null;
    DiscoveryAgent agent = null;

    public void startApp() {
        Form form = new Form("");
        stringItem = new StringItem("", "");
        Display display = Display.getDisplay(this);
        form.append(stringItem);
        display.setCurrent(form);
        try {
            agent = LocalDevice.getLocalDevice().getDiscoveryAgent();
            agent.startInquiry(DiscoveryAgent.GIAC, this);
        } catch (IOException ex) {
            ex.printStackTrace();
        }

    }

    public BTClient(){
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
    }

    public void deviceDiscovered(RemoteDevice btDevice, DeviceClass cod) {
        try {
            stringItem.setText(stringItem.getText() + "; " + btDevice.getFriendlyName(false));
            UUID uuidSet[] = new UUID[1];
            uuidSet[0] = new UUID("63236351871240528A8EA94C3ABF2B7D", false);


            agent.searchServices(null, uuidSet, btDevice, this);
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }

    public void servicesDiscovered(int transID, ServiceRecord[] servRecord) {
            stringItem.setText(stringItem.getText() + " servicesDiscovered:");
String connectionURL = servRecord[0].getConnectionURL(0, false);
        try {
            StreamConnection con = (StreamConnection) Connector.open(connectionURL);
DataOutputStream out = con.openDataOutputStream();
            String s = "test test";
            out.write(s.getBytes());
            out.flush();
            out.close();
        } catch (IOException ex) {
            ex.printStackTrace();
        }

    }
    public void serviceSearchCompleted(int transID, int respCode) {
        //throw new UnsupportedOperationException("Not supported yet.");
    }

    public void inquiryCompleted(int discType) {
        //stringItem.setText(stringItem.getText() + " inquiryCompleted");
    }
}
   
   for some reason, the servicesDiscovered is never being called when the client is e71. any ideas?
   
   does it have something to do with the null i am passing for the attrSet argument?
   
   Thanks Smiley
Logged
caragato
New user
*
Posts: 1



View Profile
Re: bluetooth client/server
« Reply #1 on: July 28, 2010, 02:26:52 pm »

Hello
I am interested in your application because I am developing a proyect using bluetooth.

I want to send an xml file from J2ME app to an aplication on a computer using J2SE.

So you know how can I do that? using server client aplication maybe?

Thank you so much.
Logged
sirajuddin
New user
*
Posts: 19



View Profile
Re: bluetooth client/server
« Reply #2 on: July 30, 2010, 05:03:47 pm »

It is possible . I done one similar kind of application
what you have to do is , first up all store the file in your phone memory and have to send that file as follows


The function service discovered in the class BTClient  have to modify as follows
that is you have to add the following lines also


 
              InputStream inStream = streamConnection.openInputStream();
              int c;
              FileConnection fc = (FileConnection)Connector.open("file:///e:/aa.txt",Connector.READ_WRITE);
            if(!fc.exists()) fc.create();
            OutputStream _out = fc.openOutputStream();
              while((c=inStream.read())!= -1){
                 _out.write(c);
             }
Logged
sirajuddin
New user
*
Posts: 19



View Profile
Re: bluetooth client/server
« Reply #3 on: July 30, 2010, 05:05:05 pm »

It is possible . I done one similar kind of application
what you have to do is , first up all store the file in your phone memory and have to send that file as follows


The function service discovered in the class BTClient  have to modify as follows
that is you have to add the following lines also


 
              InputStream inStream = streamConnection.openInputStream();
              int c;
              FileConnection fc = (FileConnection)Connector.open("file:///e:/aa.txt",Connector.READ_WRITE);
            if(!fc.exists()) fc.create();
            OutputStream _out = fc.openOutputStream();
              while((c=inStream.read())!= -1){
                 _out.write(c);
             }
Logged
Pages: [1] Print 
J2meForums  |  General Category  |  Programming (Moderators: mikkom, shendley)  |  Topic: bluetooth client/server « previous next »
Jump to:  


Login with username, password and session length

Powered by MySQL Powered by PHP J2meForums | Powered by SMF 1.0.8.
© 2001-2005, Lewis Media. All Rights Reserved.
Valid XHTML 1.0! Valid CSS!