Thu Feb 03, 2011 7:44 am
/*
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);
}
}
/*
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);
}
}
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
Powered by phpBB © phpBB Group.