Results 1 to 1 of 1
  1. #1
    balainfant is offline Member
    Join Date
    Dec 2010
    Posts
    3
    Rep Power
    0

    Default bluetooth file receiver

    i write code receive file from mobile to pc using bluetooth, it work fine in sony ericsson mobile but nokia mobile it was not working please give me some soluction , thanks in advance.

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

    package receiveapp;


    import java.io.File;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.InputStream;

    import javax.bluetooth.*;
    import javax.microedition.io.Connector;
    import javax.obex.*;
    import java.util.UUID;

    public class OBEXPutServer {

    static final String serverUUID = "22222222222222222222222222222222";
    static UUID uuid=null;
    static int count = 0;
    public static void main(String[] args) throws IOException {

    LocalDevice.getLocalDevice().setDiscoverable(Disco veryAgent.GIAC);

    SessionNotifier serverConnection = (SessionNotifier) Connector.open("btgoep://localhost:"
    + serverUUID + ";name=ObexExample");


    try
    {
    while(true) {
    RequestHandler handler = new RequestHandler();
    serverConnection.acceptAndOpen(handler);
    Thread.sleep(500);
    System.out.println("Received OBEX connection " + (++count));
    }
    }
    catch(Exception e)
    {
    System.out.println("Received OBEX connection "+e.toString());
    e.printStackTrace();
    }

    }

    private static class RequestHandler extends ServerRequestHandler {

    public int onPut(Operation op) {
    try {
    uuid = UUID.randomUUID();
    //String applicationDir="D:/WorkArea/Ramprasad/ram/NetBeansProjects/receiveapp/build/classes/Revc/";
    String applicationDir="C:/Program Files/UniverCell/UniverCellCatLog/Recv/";
    /* String applicationDir = getClass().getProtectionDomain().getCodeSource().g etLocation().getPath();
    int lastApp=applicationDir.indexOf("/receiveapp.jar");
    applicationDir=applicationDir.substring(0,lastApp) ;

    //Program%20Files
    applicationDir=applicationDir+"/Recv/";
    // System.out.println("Path="+applicationDir);
    applicationDir=applicationDir.replaceAll("Program% 20Files","Program Files");*/
    // System.out.println("Path="+applicationDir);
    java.io.InputStream is = op.openInputStream();
    HeaderSet hs = op.getReceivedHeaders();

    // HeaderSet hs = op.getType();
    String name = (String) hs.getHeader(HeaderSet.NAME);
    Long stringLength = (Long) hs.getHeader(HeaderSet.LENGTH);
    System.out.println("[client:] Path= " +name);
    File f = new File(applicationDir+uuid+".txt");
    FileOutputStream fos = new FileOutputStream (f);
    // byte b[] = new byte[1000];
    byte b[]= new byte[ (int)stringLength.longValue() ];
    int len=0;

    while ((len = is.read(b)) > 0) {
    fos.write (b, 0, len);
    }

    fos.close();
    System.out.println("AbsolutePath " + f.getAbsolutePath());

    StringBuffer buf = new StringBuffer();
    int data;
    while ((data = is.read()) != -1) {
    buf.append((char) data);
    }

    System.out.println("got:" + buf.toString());
    op.close();
    return ResponseCodes.OBEX_HTTP_OK;
    } catch (IOException e) {
    e.printStackTrace();
    // System.out.println("Insert BlurtoothDevice");
    return ResponseCodes.OBEX_HTTP_UNAVAILABLE;
    }



    }

    public int onConnect(HeaderSet request, HeaderSet reply){
    System.out.println("Hola");
    return ResponseCodes.OBEX_HTTP_OK;
    }
    }
    }

    put() method not trigger

    i attach BlueCove version 2.1.0 on winsock jar how to solve please help me.
    Last edited by balainfant; 12-01-2010 at 10:06 AM.

Similar Threads

  1. create multiple receiver
    By bhatti in forum Eclipse
    Replies: 0
    Last Post: 11-30-2010, 09:01 AM
  2. Download a file by Bluetooth in Java SE
    By danielpereira in forum New To Java
    Replies: 0
    Last Post: 10-06-2010, 08:56 PM
  3. Bluetooth FTP
    By krishna_iiita in forum CLDC and MIDP
    Replies: 0
    Last Post: 03-29-2009, 12:16 PM
  4. Replies: 0
    Last Post: 02-26-2009, 08:14 PM
  5. Questions about bluetooth
    By vision in forum CLDC and MIDP
    Replies: 1
    Last Post: 11-15-2008, 03:58 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •