software you can take with you

Sending data from a JME2 phone to PC, via SPP

Last post 04-19-2009 10:19 AM by matthewkholley. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 04-14-2009 1:39 PM

    Sending data from a JME2 phone to PC, via SPP

    Hi,

    I have been hammering at this problem for a few weeks now and can seem to get anywhere! I usually am able to find a program for one side of the communication channel so I have something that is standardised and so I can test against it, but i cant find anything!
    The scenario is this, I wish to create two sections of a system, one using Java (JME2) which just sends data (strings) to a PC server which replies to these strings with, lets say, ACKs. The following is what i've come up with so far with no cookie! PC Bluetooth adapter MAC address: 000C76D416AD

    The PC client:

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    If Not _BluetoothRadio Is Nothing Then

    Dim myByte() As Byte
    Dim _BluetoothListener As New BluetoothListener(BluetoothService.SerialPort)

    _BluetoothListener.LocalEndPoint.Address = _BluetoothRadio.LocalAddress
    _BluetoothListener.LocalEndPoint.Port = 1

    _BluetoothListener.Authenticate = False
    _BluetoothListener.Start()

    _BluetoothClient = _BluetoothListener.AcceptBluetoothClient

    Dim _NetworkStream As NetworkStream = _BluetoothClient.GetStream()

    _NetworkStream.Read(myByte, 0, 255)
    Dim returndata As String = Encoding.ASCII.GetString(myByte)

    MsgBox(returndata)

    Else

    MessageBox.Show("No devices found...")
    For Each Control As Control In Me.Controls
    Control.Enabled = False
    Next

    End If

    End Sub


    The JME2 section

    status.setText("Sending...");

    String ServiceURL = "btspp://000C76D416AD:1";
    int failPoint = 0;
    try {

    // create a server connection
    StreamConnectionNotifier notifier = (StreamConnectionNotifier) Connector.open(ServiceURL);
    failPoint = 1;

    // accept client connections
    StreamConnection connection = notifier.acceptAndOpen();
    failPoint = 2;

    // prepare to send/receive data
    byte buffer[ = new byte[100];
    String msg = "hello there";
    InputStream is = connection.openInputStream();
    failPoint = 3;

    OutputStream os = connection.openOutputStream();
    failPoint = 4;

    // send data to the client
    os.write(msg.getBytes());
    failPoint = 5;

    // read data from client
    is.read(buffer);
    connection.close();

    failPoint = 6;

    status.setText("Done!!");

    } catch(IOException e) {
    status.setText("failPoint: " + failPoint + " - " + e.toString());
    }
  • 04-18-2009 6:38 AM In reply to

    Re: Sending data from a JME2 phone to PC, via SPP

    What happens? where does it fail?

    Peter

  • 04-19-2009 10:19 AM In reply to

    Re: Sending data from a JME2 phone to PC, via SPP

    Well it doesn't fail as such, it just blocks at the

    _BluetoothClient = _BluetoothListener.AcceptBluetoothClient

    line in the PC client. I suppose this is because the phone has not successfully connected to the service correctly. The JME2 client fails at the

    StreamConnectionNotifier notifier = (StreamConnectionNotifier) Connector.open(ServiceURL);

    line. This is most probably because the PC client has not been set-up to advertise the service sufficiently?

    BTW the _BluetoothRadio.LocalAddress is "000C76D416AD"

    Thanks!

    Matt
Page 1 of 1 (3 items)
Copyright © 2001-2013 In The Hand Ltd. All rights reserved. Terms of Use and Privacy Policy. OrcsWeb's Windows Cloud Server Hosting