×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    1

    Bluetooth streaming connection in J2ME

    Hi All,

    I want to make a bluetooth connection between two mobile phones to stream audio and video. Is there anyway that I can make such a connection in J2ME? Even to stream a text via bluetooth is there any protocol in J2ME?

    Please reply if you have any idea regarding this problem as I am in a trouble with this bluetooth connection to stream data in J2ME.

    Thank you
    Thanks a lot
    Chathurika

  2. #2
    Regular Contributor
    Join Date
    Sep 2007
    Location
    Thirunelveli
    Posts
    115

    Re: Bluetooth streaming connection in J2ME

    Hi Chathurika,
    Are you asking something like RTSP protocol used for streaming from server. If just text and audio tranfer you can get details from this sample.

    http://wiki.forum.nokia.com/index.ph...hat_HelloWorld

    Regards
    Senthil

  3. #3
    Registered User
    Join Date
    Mar 2009
    Posts
    1

    Angry Bluetooth streaming connection in J2ME Nokia Mobile

    What wrong with this code please help me . i am trying to connect to printer using stream connection . i use nokia 2600 and netbeans IDE 6.5
    public void startApp() {
    try {
    localDevice = LocalDevice.getLocalDevice();
    discoveryAgent=localDevice.getDiscoveryAgent();
    boolean complete=discoveryAgent.startInquiry(DiscoveryAgent.GIAC, this);

    } catch (Throwable ex) {

    }

    }


    public void deviceDiscovered(RemoteDevice btDevice, DeviceClass cod) {
    devices.addElement(btDevice);
    frmSearching=new Form("deviceDiscovered");
    frmSearching.append("Devices Found: "+Integer.toString(devices.size()).toString());

    }
    public void servicesDiscovered(int transID, ServiceRecord[] servRecord) {
    int i;
    for (i=0;i<servRecord.length;i++){
    services.addElement(servRecord[i]);
    }
    frmSearched=new Form("servicesDiscovered");
    frmSearched.append("Services Found: "+Integer.toString(services.size()).toString());


    }

    public void serviceSearchCompleted(int transID, int respCode) {
    services.trimToSize();
    frmServSerchComp.append("Services Found: "+Integer.toString(services.size()).toString());
    /// Data Trans Start
    int i;
    /* List all the services and their names (attribute 0x100) */
    try {
    int[] aids = new int[1]; // attribute IDs
    aids[0] = 0x0100;
    for(i = 0; i < services.size(); i++) {
    ServiceRecord s = (ServiceRecord)services.elementAt(i); s.getConnectionURL(0, true); s.getAttributeValue(0x0100); s.populateRecord(aids);
    }

    URL=((ServiceRecord)(services.elementAt(0))).getConnectionURL(0, true);

    frmServSerchComp.append("Connecteion Start:");
    // StreamConnectionNotifier notifier = (StreamConnectionNotifier) Connector.open(((ServiceRecord)(services.elementAt(0))).getConnectionURL(0, true));
    // accept client connections
    StreamConnectionNotifier notifier = (StreamConnectionNotifier) Connector.open(URL);
    StreamConnection c = notifier.acceptAndOpen();
    byte buffer[] = new byte[100];
    int[] testPacket = {0x7E,0xb4,0x04,0xb0};
    int[] msg = {0x7E,0xb4,0x04,0xb0};
    int res;
    InputStream iss = c.openInputStream(); OutputStream oss = c.openOutputStream(); oss.flush();

    // Send To write Stream connection
    frmServSerchComp.append("9"); res=sendData(testPacket,testPacket.length,c); frmServSerchComp.append("RES"+res);
    try {
    // send data to the client
    oss.write(msg.toString().getBytes());
    } catch (Throwable e) {
    getErrorForm(e);
    }
    // read data from client
    iss.read(buffer);
    frmServSerchComp.append("RLY"+buffer.toString());

    for(i = 0; i < services.size(); i++) {
    ServiceRecord s = (ServiceRecord)services.elementAt(i);

    s.populateRecord(aids);
    }


    } catch (Throwable e) {
    getErrorForm(e);
    }
    }

    public void inquiryCompleted(int discType) {
    devices.trimToSize();
    int i;

    choose=new List(Integer.toString(devices.size()).toString()+"Devices Select List",List.IMPLICIT);

    try {
    for( i=0;i<devices.size();i++){
    RemoteDevice dremoteDevice=(RemoteDevice)devices.elementAt(i);
    choose.append(dremoteDevice.getBluetoothAddress(),null);
    }

    Display.getDisplay(this).setCurrent(choose);

    resumeRequest();
    for( i=0;i<devices.size();i++){
    RemoteDevice dremoteDevice=(RemoteDevice)devices.elementAt(i);
    choose.set(i,dremoteDevice.getFriendlyName(false),null);
    }

    } catch (Throwable e) {
    getErrorForm(e);
    }
    .....

    }

    public void commandAction(Command c, Displayable d) {
    ....
    if(d==frmError){
    if(c==ok){
    ...
    }else if(c==cancel){
    switchDisplayable(null,null);
    destroyApp(true);
    notifyDestroyed();
    }
    }
    if(d==frmSearched){
    if(c==ok){
    serviceSearchCompleted(SERVICE_SEARCH_COMPLETED, SERVICE_SEARCH_COMPLETED);
    frmSearched.append("OK Pressed");
    }else if(c==cancel){
    switchDisplayable(null,null);
    destroyApp(true);
    notifyDestroyed();
    }else{
    serviceSearchCompleted(SERVICE_SEARCH_COMPLETED, SERVICE_SEARCH_COMPLETED);
    }
    }
    if(d==choose){
    if(c==ok){
    try {
    List chooses = (List)d;
    /* Get the selected device from the devices list */
    RemoteDevice dd = (RemoteDevice)devices.elementAt(chooses.getSelectedIndex());
    /* Inquire about Serial Port services (UUID 0x1101) */
    UUID[] query = new UUID[1];
    query[0] = new UUID(0x1101);
    services = new java.util.Vector();
    javax.bluetooth.LocalDevice.getLocalDevice().getDiscoveryAgent().searchServices(null, query, dd, this);

    } catch (Throwable e) {
    getErrorForm(e);
    }
    }else if(c==cancel){
    switchDisplayable(null,null);
    destroyApp(true);
    notifyDestroyed();
    }
    }
    if(d==frmServSerchComp){
    if(c==ok){
    try {

    List chooses = (List)d;
    /* Get the selected device from the devices list */
    RemoteDevice dd = (RemoteDevice)devices.elementAt(chooses.getSelectedIndex());
    /* Inquire about Serial Port services (UUID 0x1101) */
    UUID[] query = new UUID[1];
    query[0] = new UUID(0x1101);
    services = new java.util.Vector();
    javax.bluetooth.LocalDevice.getLocalDevice().getDiscoveryAgent().searchServices(null, query, dd, this);

    } catch (Throwable e) {
    getErrorForm(e);
    }
    }else if(c==cancel){
    switchDisplayable(null,null);
    destroyApp(true);
    notifyDestroyed();
    }
    }
    }


    public int sendData(int[] packet,int length,StreamConnection c)
    {
    frmServSerchComp.append("10");
    int counter = 0;
    int response = 0;
    InputStream inputStream = null;//c.openInputStream();
    OutputStream outputStream = null;// c.openOutputStream();

    for(counter =1; counter <= 3; counter++)
    {
    try
    {

    //outputStream =c.getOutputStream();
    inputStream = c.openInputStream();
    outputStream = c.openOutputStream();
    for( int i =0 ; i < length ;i++){

    outputStream.write(packet[i]);
    }
    outputStream.close();

    } catch (Throwable e) { getErrorForm(e);}

    int c3 = 0;
    try {
    while (inputStream.available() > 0) {
    c3 = inputStream.read();
    }
    setResponse(c3);
    inputStream.close();
    } catch (Throwable e) { getErrorForm(e);}
    response = getResponse();
    if(response != 0x80 && timeoutFlag == false){
    // set the responseByte to 0x00 before returning..
    responseByte = 0x00;
    return response;
    }
    else if(response != 0x80 && timeoutFlag == true){
    timeoutFlag = false;
    System.out.println("Retrying");
    continue;
    }
    else{
    // set the responseByte to 0x00 before returning..
    responseByte = 0x00;
    return response;
    }

    }
    frmServSerchComp.append("11");
    if(counter > 3){
    // set the responseByte to 0x00 before returning..
    responseByte = 0x00;
    return 0x44;
    }
    else{
    // set the responseByte to 0x00 before returning..
    responseByte = 0x00;
    return 0x00;
    }

    }
    private synchronized void setResponse(int response)
    {
    while (available == true) {
    try {
    wait();
    } catch (InterruptedException e) {
    }
    }
    responseByte = response;
    available = true;

    notifyAll();
    }


    private synchronized int getResponse()
    {
    int timeout = 100;
    while (available == false) {
    try {
    wait(3);
    } catch (InterruptedException e) {
    }
    if(--timeout == 0){
    timeoutFlag = true;
    break;
    }
    }
    available = false;
    notifyAll();
    return responseByte;

    }


    }

Similar Threads

  1. Streaming Video over Bluetooth
    By davmt in forum Streaming and Video
    Replies: 3
    Last Post: 2009-03-27, 02:00
  2. Bluetooth Connection Problem
    By atonical in forum Symbian
    Replies: 4
    Last Post: 2008-11-28, 11:20
  3. how to open a bluetooth connection from J2ME application
    By santoshtn84 in forum [Archived] Other Programming Discussion 关于其他编程技术的讨论
    Replies: 1
    Last Post: 2007-05-16, 10:29
  4. Detect connection Bluetooth or GPRS
    By curcio1 in forum Symbian Networking & Messaging (Closed)
    Replies: 3
    Last Post: 2004-05-04, 15:29

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×