Results 1 to 2 of 2
  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.

  2. #2
    balainfant is offline Member
    Join Date
    Dec 2010
    Posts
    3
    Rep Power
    0

    Default file transfer problem

    receive file from mobile to pc its work fine.but one time only its work, its came BlueCove stack shutdown completed and close application . its j2se based.
    i want multi time run that application whats my wrong please help me
    i attach code bluecove2.1,avetan jar files

    my code is belove:

    package univercellfileresiver;


    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.microedition.io.*;
    import java.io.*;
    //import net.benhui.bluecove.spp_bt;
    //import javax.bluetooth.*;
    //import javax.obex.*;

    //import javax.bluetooth.*;
    //import javax.obex.*;


    import de.avetana.javax.obex.HeaderSet;
    import de.avetana.javax.obex.Operation;
    import de.avetana.javax.obex.PasswordAuthentication;
    import de.avetana.javax.obex.ResponseCodes;
    import de.avetana.javax.obex.ServerRequestHandler;

    import de.avetana.javax.obex.SessionNotifier;
    import java.util.UUID;
    import javax.bluetooth.DiscoveryAgent;
    import javax.bluetooth.LocalDevice;
    public class FileResiver {
    DiscoveryAgent agent;
    static int count = 0;
    public static UUID fileUUid=null;
    public static void main(String[] args) throws IOException {
    String uuid="9106";
    LocalDevice.getLocalDevice().setDiscoverable(Disco veryAgent.GIAC);// obtain reference to singleton
    // device.setDiscoverable(DiscoveryAgent.GIAC); // set Discover mode to LIAC
    String url = "btgoep://localhost:" + uuid + ";name=HTBP";
    SessionNotifier sn = (SessionNotifier)OBEXConnector.open(url);
    while(true)
    {
    RequestHandler handler = new RequestHandler();
    sn.acceptAndOpen(handler);
    fileUUid = UUID.randomUUID();
    count++;
    System.out.println("Received OBEX connection " + (count));
    }
    }

    private static class RequestHandler extends ServerRequestHandler {
    // @Override
    public int onConnect(HeaderSet request, HeaderSet reply){
    try
    {
    System.out.println("Hola");
    return ResponseCodes.OBEX_HTTP_OK;
    }catch(Exception e)
    {
    return 0;
    }
    }


    public int onPut(Operation op) {
    try {
    fileUUid = UUID.randomUUID();
    //String applicationDir="D:/WorkArea/Ramprasad/ram/NetBeansProjects/receiveapp/build/classes/Revc/";
    String applicationDir="C:/Program Files/UniverCell/UniverCellCatLog/Recv/";
    //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 response = hs.connect(hs);
    // 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+fileUUid+".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());
    op.close();
    return ResponseCodes.OBEX_HTTP_OK;
    } catch (IOException e) {
    e.printStackTrace();
    // System.out.println("Insert BlurtoothDevice");
    return ResponseCodes.OBEX_HTTP_UNAVAILABLE;
    }
    }
    }

    }
    please help me

Similar Threads

  1. bluetooth file receiver
    By balainfant in forum New To Java
    Replies: 0
    Last Post: 12-01-2010, 10:04 AM
  2. create multiple receiver
    By bhatti in forum Eclipse
    Replies: 0
    Last Post: 11-30-2010, 10:01 AM
  3. Download a file by Bluetooth in Java SE
    By danielpereira in forum New To Java
    Replies: 0
    Last Post: 10-06-2010, 09:56 PM
  4. Bluetooth FTP
    By krishna_iiita in forum CLDC and MIDP
    Replies: 0
    Last Post: 03-29-2009, 01:16 PM
  5. Replies: 0
    Last Post: 02-26-2009, 09:14 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
  •