本文整理汇总了Java中javax.microedition.io.StreamConnectionNotifier类的典型用法代码示例。如果您正苦于以下问题:Java StreamConnectionNotifier类的具体用法?Java StreamConnectionNotifier怎么用?Java StreamConnectionNotifier使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StreamConnectionNotifier类属于javax.microedition.io包,在下文中一共展示了StreamConnectionNotifier类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: PAKBluetoothPairingHandler
import javax.microedition.io.StreamConnectionNotifier; //导入依赖的package包/类
public PAKBluetoothPairingHandler(String password, String eMail,
String firstName, String lastName, String deviceName,
X509Certificate ownerCertEnc, X509Certificate ownerCertSign,
Map<String, X509Certificate> knownDevices,
Collection<VCard> knownContacts) throws IOException {
super(PairingType.SLAVE, password, eMail, firstName, lastName,
deviceName, ownerCertEnc, ownerCertSign, knownDevices,
knownContacts);
UUID uuid = new UUID(0x1101); // TODO: Create new unique UUID
String connectionString = "btspp://localhost:" + uuid
+ ";name=PanboxImportListener;encrypt=false;authenticate=false";
streamConnNotifier = (StreamConnectionNotifier) Connector.open(
connectionString, Connector.READ_WRITE);
ServiceRecord record = LocalDevice.getLocalDevice().getRecord(
streamConnNotifier);
logger.debug("PAKBluetoothPairingHandler : connection is up at: "
+ record.getConnectionURL(0, false));
}
示例2: run
import javax.microedition.io.StreamConnectionNotifier; //导入依赖的package包/类
public void run() {
try {
StreamConnectionNotifier server = (StreamConnectionNotifier) Connector.open("socket://:" + port);
Client currentClient = null;
while (true) {
StreamConnection connection = server.acceptAndOpen();
System.out.println("Client Connected.");
if (currentClient != null) {
currentClient.kill();
}
currentClient = new Client(connection);
currentClient.start();
}
} catch (Exception e) {
e.printStackTrace();
}
}
示例3: startServer
import javax.microedition.io.StreamConnectionNotifier; //导入依赖的package包/类
/**
* Opens a server connection ({@link StreamConnectionNotifier}) and starts
* up {@link IncomingClientListener} if succeeded. If opening of the
* connection failed, the application will be exited.
*/
public void startServer() {
System.out.println();
System.out.println();
System.out.println("Device:");
System.out.println("\t" + device.getFriendlyName());
System.out.println("\t" + device.getBluetoothAddress());
System.out.println();
System.out.println();
try {
System.out.println("Opening up server connection...");
server = (StreamConnectionNotifier) Connector.open(URL);
} catch (IOException e) {
System.out.println("Failed open server connection: " + e.getMessage());
System.exit(1);
}
System.out.println("Server up and running!");
IncomingClientListener listener = new IncomingClientListener(server);
listener.start();
setAllowClientInput(true);
}
示例4: tryToClose
import javax.microedition.io.StreamConnectionNotifier; //导入依赖的package包/类
private void tryToClose(@Nullable StreamConnectionNotifier ss) {
try {
if (ss != null) ss.close();
} catch (IOException e) {
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
} finally {
callback.transportDisabled();
}
}
示例5: acceptContactConnections
import javax.microedition.io.StreamConnectionNotifier; //导入依赖的package包/类
private void acceptContactConnections(StreamConnectionNotifier ss) {
while (true) {
StreamConnection s;
try {
s = ss.acceptAndOpen();
} catch (IOException e) {
// This is expected when the socket is closed
if (LOG.isLoggable(INFO)) LOG.info(e.toString());
return;
}
backoff.reset();
callback.incomingConnectionCreated(wrapSocket(s));
if (!running) return;
}
}
示例6: bluetoothServer
import javax.microedition.io.StreamConnectionNotifier; //导入依赖的package包/类
/**
* start server creating an UUID and a connection String,
* then waiting for a device to connect
*/
private void bluetoothServer() {
if (sendReciveMessageThread.isAlive()) {
sendReciveMessageThread.interrupt();
}
try {
//Create a UUID for SPP
UUID uuid = new UUID("1101", true);
//Create the servicve url
String connectionString = "btspp://localhost:" + uuid + ";name=Sample SPP Server";
//open server url
streamConnNotifier = (StreamConnectionNotifier) Connector.open(connectionString);
//Wait for client connection
System.out.println("\nServer Started. Waiting for clients to connect...");
StreamConnection connection = streamConnNotifier.acceptAndOpen();
System.out.println("Remote device address: " + RemoteDevice.getRemoteDevice(connection).getBluetoothAddress());
System.out.println("Remote device name: " + RemoteDevice.getRemoteDevice(connection).getFriendlyName(true));
//the stream is opened both in and out
outStream = connection.openOutputStream();
inStream = connection.openInputStream();
connectionIsAvaible = true;
SingletonStaticGeneralStats.getInstance().setBluetoothServerCreated(true);
sendBluetoothMessage();
} catch (IOException e) {
e.printStackTrace();
//in case of problems, the connection is stopped
closeConnection();
}
}
示例7: getStreamConnection
import javax.microedition.io.StreamConnectionNotifier; //导入依赖的package包/类
public javax.microedition.io.StreamConnection getStreamConnection(
javax.microedition.io.Connection connection) throws IOException {
if (connection instanceof StreamConnectionNotifier) {
return ((StreamConnectionNotifier) connection).acceptAndOpen();
} else if (connection instanceof StreamConnection) {
return (javax.microedition.io.StreamConnection) connection;
} else {
throw new IllegalStateException("Connection class not known. "
+ connection.getClass().getName());
}
}
示例8: startserver
import javax.microedition.io.StreamConnectionNotifier; //导入依赖的package包/类
public void startserver() {
try {
String url = "btspp://localhost:" + uuid +
// new UUID( 0x1101 ).toString() +
";name=File Server";
StreamConnectionNotifier service = (StreamConnectionNotifier) Connector.open(url);
StreamConnection con = service.acceptAndOpen();
OutputStream dos = con.openOutputStream();
InputStream dis = con.openInputStream();
InputStreamReader daf = new InputStreamReader(System.in);
BufferedReader sd = new BufferedReader(daf);
RemoteDevice dev = RemoteDevice.getRemoteDevice(con);
String greeting = "hi";
dos.write(greeting.getBytes(Charset.forName("utf-8")));
dos.flush();
byte buffer[] = new byte[1024];
int bytes_read = dis.read(buffer);
String received = new String(buffer, 0, bytes_read, Charset.forName("utf-8"));
System.out.println
("Message:" + received + "From:"
+ dev.getBluetoothAddress());
// con.close();
} catch (IOException e) {
System.err.print(e.toString());
}
}
示例9: tryToClose
import javax.microedition.io.StreamConnectionNotifier; //导入依赖的package包/类
private void tryToClose(StreamConnectionNotifier ss) {
try {
if(ss != null) ss.close();
} catch(IOException e) {
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
}
}
示例10: acceptContactConnections
import javax.microedition.io.StreamConnectionNotifier; //导入依赖的package包/类
private void acceptContactConnections(StreamConnectionNotifier ss) {
while(true) {
StreamConnection s;
try {
s = ss.acceptAndOpen();
} catch(IOException e) {
// This is expected when the socket is closed
if(LOG.isLoggable(INFO)) LOG.info(e.toString());
return;
}
callback.incomingConnectionCreated(wrapSocket(s));
if(!running) return;
}
}
示例11: OBEXSessionNotifierImpl
import javax.microedition.io.StreamConnectionNotifier; //导入依赖的package包/类
/**
* Applications should not used this function.
*
* @exception Error
* if called from outside of BlueCove internal code.
*/
public OBEXSessionNotifierImpl(StreamConnectionNotifier notifier, OBEXConnectionParams obexConnectionParams)
throws IOException, Error {
Utils.isLegalAPICall(fqcnSet);
this.notifier = notifier;
this.obexConnectionParams = obexConnectionParams;
}
示例12: close
import javax.microedition.io.StreamConnectionNotifier; //导入依赖的package包/类
public void close() throws IOException {
StreamConnectionNotifier n = this.notifier;
this.notifier = null;
if (n != null) {
n.close();
}
}
示例13: run
import javax.microedition.io.StreamConnectionNotifier; //导入依赖的package包/类
public boolean run(String name) {
try {
StreamConnectionNotifier server = (StreamConnectionNotifier) Connector
.open("btspp://localhost:"
+ uuid
+ ";name="
+ name
+ ";authorize=false;authenticate=false;encrypt=false");
System.out.println("Server started " + name);
StreamConnection conn = server.acceptAndOpen();
System.out.println("Server received connection");
DataInputStream dis = new DataInputStream(conn.openInputStream());
System.out.print("Got message[");
System.out.print(dis.readUTF());
System.out.println("]");
dis.close();
conn.close();
server.close();
return true;
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
示例14: ListeningTask
import javax.microedition.io.StreamConnectionNotifier; //导入依赖的package包/类
private ListeningTask(StreamConnectionNotifier serverSocket) {
this.serverSocket = serverSocket;
}
示例15: BluetoothKeyAgreementListener
import javax.microedition.io.StreamConnectionNotifier; //导入依赖的package包/类
private BluetoothKeyAgreementListener(BdfList descriptor,
StreamConnectionNotifier ss) {
super(descriptor);
this.ss = ss;
}