Total members 11890 |It is currently Wed Apr 24, 2024 8:41 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





Mobile to PC connection using bluetooth
sir please run this attachments please sir as soon as possible
sir when i start the server with the internet option it making the connection
but it not making with the bluetooth option
sir this folder will be open with the new project and choose 4th option"existing source"
sir please help
Code:
/*
    JM2PC - Java Mobile to PC
    Copyright (C) 2005-2009 - Walter Alves Wanderley
    Recife - PE - Brazil

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

package jm2pc.server.connection.bluetooth;

import java.io.IOException;
import java.util.Vector;

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

import jm2pc.server.connection.ServerManager;
import jm2pc.server.log.Loggable;


public class ServerManagerBluetooth extends ServerManager {

    private StreamConnectionNotifier connectionNotifier;

    private int clientNumber;

    private boolean authenticate;
    
    private boolean authorize
;

    private boolean encrypt;

    private Vector<StreamConnection> connections;

    public ServerManagerBluetooth(Loggable log) {
        super(log);
        clientNumber = 0;

        connections = new Vector<StreamConnection>();

    }

    public boolean isAuthenticate() {
        return authenticate;
    }

    public void setAuthenticate(boolean authenticate) {
        this.authenticate = authenticate;
    }
        
    public boolean isAuthorize
() {
        return authorize;
    }

    public void setAuthorize(boolean authorize) {
        this.authorize = authorize;
    }

    public boolean isEncrypt() {
        return encrypt;
    }

    public void setEncrypt(boolean encrypt) {
        this.encrypt = encrypt;        
    
}

    public void start() throws Exception {
        
        UUID uuid 
= new UUID(0x1101);
        StringBuffer sbParams = new StringBuffer();
        sbParams.append(";authenticate=");
        sbParams.append(String.valueOf(authenticate));
        sbParams.append(";authorize=");
        sbParams.append(String.valueOf(authorize));
        sbParams.append(";encrypt=");
        sbParams.append(String.valueOf(encrypt));
        sbParams.append(";name=iRAService");

        String url = "btspp://localhost:" + uuid.toString()
                + sbParams.toString();

        try {
            connectionNotifier = (StreamConnectionNotifier) Connector.open(url);
            setServerStarted(true);
            showStartMessage("Bluetooth -- JSR-82 -- iRAService  -- ");
        } catch(IOException ioe) {
            throw new IOException(ioe.getMessage() + "\n\nTry to restart your Bluetooth adaptor or"+
"...\n\n\t1 - Try to start with the Bluetooth COMM (Virtual Serial Port Service) mode."
                                 +"\n\n\t2 - Select COMM mode and the COM Port used for"+"
 Incomming bluetooth connections.\n"
);
        }                
            
        Thread t 
= new Thread() {
            public void run() {
                StreamConnection s;
                while (isServerStarted()) {
                    try {
                        s = connectionNotifier.acceptAndOpen();
                        startSession(s);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        };
        t.start();

    }

    private void startSession(StreamConnection s) throws IOException {
        addConnection(s);
        clientNumber++;
        String password = getPassword();
        int timeout = getTimeout();
        SessionManagerBluetooth service = new SessionManagerBluetooth(s,
                getLog(), clientNumber, password, timeout);
        Thread t = new Thread(service);
        t.start();
    }

    public void stop() throws IOException {
        setServerStarted(false);
        disconnectClients();
        if (connectionNotifier != null)
            connectionNotifier.close();

        showStoppedMessage();
    }

    private void addConnection(StreamConnection s) {
        connections.addElement(s);
    }

    protected void disconnectClients() {
        int conectados = 0;
        for (int i = 0; i < connections.size(); i++) {
            StreamConnection s = connections.elementAt(i);
            try {
                conectados++;
                s.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        connections.clear();

        showDisconnectMessage(conectados);
    }

}
 


Code:
/*
    JM2PC - Java Mobile to PC
    Copyright (C) 2005-2009 - Walter Alves Wanderley
    Recife - PE - Brazil

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

package jm2pc.server.gui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JComboBox;

public class BluetoothConnectionTypeComboBox extends JComboBox {

    public static final long serialVersionUID = 1l;
    
    public static final String TYPE_BLUETOOTH_COMM 
= "COMM";
    public static final String TYPE_BLUETOOTH_JSR82 = "JSR-82";    
    
    public BluetoothConnectionTypeComboBox
(final ServerFrame servidorFrame) {
        super();                
        
        addItem
(TYPE_BLUETOOTH_COMM);
        addItem(TYPE_BLUETOOTH_JSR82);        
        
        setSelectedItem
(TYPE_BLUETOOTH_COMM);
        
        ActionListener listener 
= new ActionListener() {
            public void actionPerformed(ActionEvent event) {
                servidorFrame.alterarTipo();
            }
        };
        
        addActionListener
(listener);
        
        setEditable
(false);
    }

}
 





Attachments:
Source.rar [158.68 KiB]
Downloaded 872 times
Author:
Newbie
User avatar Posts: 5
Have thanks: 0 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : Mobile to PC connection using Bluetooth
 Bluetooth connection using C# (won't work)     -  
 mobile to pc in bluetooth in java     -  
 sending sms from bluetooth mobile to pc     -  
 connecting to pc from mobile using bluetooth in java     -  
 Connecting to PC from mobile using bluetooth in java     -  
 connecting PC with mobile using bluetooth code in java     -  
 bluetooth in j2me     -  
 MultiClient Bluetooth Chat     -  
 bluetooth communication in java     -  
 Bluetooth demo in WTK25 does not work     -  



Topic Tags

Java J2ME, Java Networking






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com