BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 10-23-2009, 12:34 PM   #1 (permalink)
New Member
 
Join Date: Oct 2009
Model: 8330m
PIN: N/A
Carrier: Sprint
Posts: 2
Post Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy OBEX Bluetooth Server

Please Login to Remove!

I am trying to create a bluetooth server. this should work not unlike going to media> options>Receive Using Bluetooth. I am having a very hard time finding any code that would help me.

Basically this needs to run in the background. When the paired device sends a file, the software should accept the file and save it in a folder.

This is what I have so far but it gives a "Java.Lang.Error" on the red line.

Code:
import javax.bluetooth.BluetoothStateException;
import javax.bluetooth.DiscoveryAgent;
import javax.bluetooth.LocalDevice;
import javax.bluetooth.RemoteDevice;
import javax.bluetooth.ServiceRecord;
import javax.bluetooth.UUID;

import javax.microedition.io.Connector;
import javax.microedition.io.StreamConnection;
import javax.microedition.io.StreamConnectionNotifier;

import javax.obex.*;  






public class Test extends ServerRequestHandler{

	private static final UUID SERVICE_UUID = new UUID("00112233445566778899AABBCCDDEEFF", false);
	//Server-side URL for the service

	private static final String SERVER_URL = "btgoep://localhost:" + SERVICE_UUID + ";name=SSPEx";


public Test() throws BluetoothStateException, IOException{
	startServer();
}





//Registers our SDDB record

public  void startServer() throws BluetoothStateException, IOException
{
	
		StreamConnectionNotifier btService = (StreamConnectionNotifier) Connector.open(SERVER_URL, Connector.READ_WRITE);
	
 
javax.bluetooth.ServiceRecord service = LocalDevice.getLocalDevice().getRecord(btService); 

System.out.println("Server started. Connect at " + service.getConnectionURL(ServiceRecord.AUTHENTICATE_ENCRYPT, false));

 if (!LocalDevice.getLocalDevice().setDiscoverable(DiscoveryAgent.LIAC))       
 System.out.println("Cannot switch device to discoverable mode. Will launch the service anyway but you need to manually switch the device to discoverable mode");    
 
StreamConnection btConnection = btService.acceptAndOpen();
RemoteDevice remoteDevice = RemoteDevice.getRemoteDevice(btConnection);   

System.out.println("Received a connection from " + remoteDevice.getFriendlyName(false));
}

Last edited by comanchesniper : 10-23-2009 at 12:36 PM.
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Vintage DEC Digital M8639-YB RDRX Disk Controller Board 50-15649-01 E1 M8639
$125.0
Vintage DEC Digital M8639-YB RDRX Disk Controller Board 50-15649-01 E1 M8639  pictureVintage SIGNODE Crimping W14 Tool 17.5" long pat#1784123 dec9 1930 /N12167
$19.72
Vintage SIGNODE Crimping W14 Tool  17.5HSS 12PCS VALVE SEAT & FACE CUTTER 45DEC 30DEC 20DEC FOR VINTAGE CAR, BIKES,JEEP
$163.99
HSS 12PCS VALVE SEAT & FACE CUTTER 45DEC 30DEC 20DEC FOR VINTAGE CAR, BIKES,JEEP pictureHSS 21PCS VALVE SEAT & FACE CUTTER 45DEC 30DEC 20DEC - VINTAGE CAR,BIKES, JEEP
$222.99
HSS 21PCS VALVE SEAT & FACE CUTTER 45DEC 30DEC 20DEC - VINTAGE CAR,BIKES, JEEP pictureVintage Working Pelouze Model Y-5 Postal Scale Up To 7 Lb. Dec 31, 1975
$18.95
Vintage Working Pelouze Model Y-5 Postal Scale Up To  7 Lb. Dec 31, 1975   picture






Copyright 2004-2016 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.