本文整理汇总了Java中javax.microedition.io.StreamConnectionNotifier.acceptAndOpen方法的典型用法代码示例。如果您正苦于以下问题:Java StreamConnectionNotifier.acceptAndOpen方法的具体用法?Java StreamConnectionNotifier.acceptAndOpen怎么用?Java StreamConnectionNotifier.acceptAndOpen使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.microedition.io.StreamConnectionNotifier
的用法示例。
在下文中一共展示了StreamConnectionNotifier.acceptAndOpen方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
}
示例2: 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;
}
}
示例3: 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();
}
}
示例4: 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());
}
}
示例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;
}
callback.incomingConnectionCreated(wrapSocket(s));
if(!running) return;
}
}
示例6: 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;
}
}
示例7: run
import javax.microedition.io.StreamConnectionNotifier; //导入方法依赖的package包/类
/**
* This method is called when the ConnectionListener thread is started in the
* constructor.
*
* It continously listens for incoming connections matching the
* serviceID of the peer2me framework. The listener is "passive" and opens a
* connection waiting for a device to take contact.
* If an incoming connetion occurs, information is abstracted from the remote
* node, and a node object containing this connection is created and added
* to the group on the local node.
*
*/
public void run(){
try{
// Opens the stream
connectionNotifier = (StreamConnectionNotifier) Connector.open(connectionURL);
while(true){//(!failed || !shutdown){
// Returns a StreamConnection that represents a server side socket connection.
connection = (StreamConnection)connectionNotifier.acceptAndOpen();
// If the connection is successful a representation of the remote node is created
if(!failed || !shutdown){
// Creates the node who found "me" (as a participant) and opens a connection
String address = Network.getInstance().getNodeAddress(connection);
Node remoteNode = new Node(address,connection);
// Starts the InputThread in NodeConnection again since we have a connection
remoteNode.getNodeConnection().openInputStream();
// Adds the node who found "me" to the group containing all found nodes
currentNetwork.getFrameworkFrontEnd().getGroup().addParticipant(remoteNode);
// This Node is discovered and connected by another Node the currentNetwork is notified
currentNetwork.connectionEstablished();
log.logConnection(new StringBuffer().append("Connected successfully to a node with address: ").append(address).toString());
}
}
}catch(IOException ioe) {
log.logException("ConnectionListener.run()",ioe, true);
failed = true;
}catch(SecurityException se) {
log.logException("ConnectionListener.run()",se, true);
failed = true;
}catch(IllegalArgumentException iae){
log.logException("ConnectionListener.run()",iae, true);
failed = true;
}
}