Sun Java Wireless Toolkit - sending files via bluetooth pc to pc

i want to send a file from pc to pc via bluetooth

my code is :

public void sendFile2Mobile(String adr) {

try {

JFileChooser fc = new JFileChooser();

fc.setAccessory(new FindAccessory());

int result = fc.showOpenDialog(null);

System.out.println("result " + result + ":");

System.out.println(fc.getSelectedFile());

switch (result) {

case JFileChooser.APPROVE_OPTION:

//System.out.println("Ok");

File selFile = fc.getSelectedFile();

System.out.println("selFile path \n" + selFile);

System.out.println("selFile name \n" + selFile.getName());

//String adr = "btgoep://000e6d74399a:9";

// no lookup code here ?put your phone's bt address here!

ClientSession cs = (ClientSession) OBEXConnector.open(adr);

System.out.println("opening");

HeaderSet hs = cs.connect(cs.createHeaderSet());

System.out.println("created header set");

//byte text[] = "Chat Send File Test Message from PC".getBytes("iso-8859-1");

byte text[] = getBytesFromFile(selFile);

String fileName = selFile.getName();

hs.setHeader(HeaderSet.NAME, fileName);

hs.setHeader(HeaderSet.TYPE, "text");

//hs.setHeader(0x49, text); // if everything fits inside a packet, the data can be packed in the PUT command

System.out.println("putting....");

Operation po = cs.put(hs);

System.out.println("put....");

po.openOutputStream().write(text);

po.close();

cs.disconnect(null);

cs.close();

System.out.println("closed...");

// Approve (Open or Save) was clicked

break;

case JFileChooser.CANCEL_OPTION:

// Cancel or the close-dialog icon was clicked

break;

case JFileChooser.ERROR_OPTION:

// The selection process did not complete successfully

break;

}

} catch (Throwable e) {

e.printStackTrace();

}

}

it gives me this error :

[WARNING] You are using BlueCove Connector [WARNING]

java.io.IOException: Failed to connect socket

at com.intel.bluetooth.BluetoothPeer.connect(Native Method)

at com.intel.bluetooth.BluetoothConnection.<init>(BluetoothConnection.java:52)

at javax.microedition.io.Connector.open(Connector.java:125)

at de.avetana.obexsolo.OBEXConnector.open(OBEXConnector.java:103)

at ChatMessageTxn.sendFile2Mobile(ChatMessageTxn.java:155)

at ChatMessageTxn.jMenuItem3ActionPerformed(ChatMessageTxn.java:112)

at ChatMessageTxn.access$200(ChatMessageTxn.java:18)

at ChatMessageTxn$3.actionPerformed(ChatMessageTxn.java:66)

at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1786)

at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1839)

at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)

at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)

at javax.swing.AbstractButton.doClick(AbstractButton.java:289)

at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1113)

at javax.swing.plaf.basic.BasicMenuItemUI$MouseInputHandler.mouseReleased(BasicMenuItemUI.ja

va:943)

at java.awt.Component.processMouseEvent(Component.java:5100)

at java.awt.Component.processEvent(Component.java:4897)

at java.awt.Container.processEvent(Container.java:1569)

at java.awt.Component.dispatchEventImpl(Component.java:3615)

at java.awt.Container.dispatchEventImpl(Container.java:1627)

at java.awt.Component.dispatchEvent(Component.java:3477)

at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3483)

at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3198)

at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128)

at java.awt.Container.dispatchEventImpl(Container.java:1613)

at java.awt.Window.dispatchEventImpl(Window.java:1606)

at java.awt.Component.dispatchEvent(Component.java:3477)

at java.awt.EventQueue.dispatchEvent(EventQueue.java:456)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)

Plz help

[4604 byte] By [c4cainea] at [2007-11-26 23:21:47]
# 1

this line:

ClientSession cs = (ClientSession) OBEXConnector.open(adr);

calls the the MAC ADRESS of the mobile phone provided in adr

but by using this line //String adr = "btgoep://000e6d74399a:9"; the String adr wil never be difined. remove the //

are you sure that

//String adr = "btgoep://000e6d74399a:9"; is correct?

what could be the problem that the program is trying to connect to the wrong port! (in this case its port 9) it has to the port on your mobile phone/device thats supports Object Push Profile otherwise it won't work. a lot of problems start there.

Zijst005a at 2007-7-10 14:26:20 > top of Java-index,Java Mobility Forums,Java ME Technologies...