Results 1 to 2 of 2
Thread: bluetooth file receiver
- 12-01-2010, 10:06 AM #1
Member
- Join Date
- Dec 2010
- Posts
- 3
- Rep Power
- 0
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.
- 12-07-2010, 05:50 AM #2
Member
- Join Date
- Dec 2010
- Posts
- 3
- Rep Power
- 0
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
-
bluetooth file receiver
By balainfant in forum New To JavaReplies: 0Last Post: 12-01-2010, 09:04 AM -
create multiple receiver
By bhatti in forum EclipseReplies: 0Last Post: 11-30-2010, 09:01 AM -
Download a file by Bluetooth in Java SE
By danielpereira in forum New To JavaReplies: 0Last Post: 10-06-2010, 08:56 PM -
Bluetooth FTP
By krishna_iiita in forum CLDC and MIDPReplies: 0Last Post: 03-29-2009, 12:16 PM -
Transfering files over Bluetooth (with javax.bluetooth)
By weber10 in forum CLDC and MIDPReplies: 0Last Post: 02-26-2009, 08:14 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks