@Test public void accept_timeout() { try { serverSocket.accept(200); fail(); } catch (IOException expected) { // Expected } }
public void cancel() { try { mServerSocket.close(); } catch (IOException e) { e.printStackTrace(); } }
@Test public void accept() throws Exception { BluetoothDevice btDevice = ShadowBluetoothDevice.newInstance("DE:AD:BE:EE:EE:EF"); shadowOf(serverSocket).deviceConnected(btDevice); BluetoothSocket clientSocket = serverSocket.accept(); assertThat(clientSocket.getRemoteDevice()).isSameAs(btDevice); }
public void cancel() { try { mmServerSocket.close(); } catch (IOException e) {} } }
private class Server_Connect_Thread extends Thread { private final BluetoothServerSocket mmServerSocket; private boolean running = true; public Server_Connect_Thread() { BluetoothServerSocket tmp = null; try { tmp = bluetooth_adapter.listenUsingRfcommWithServiceRecord("NAME", uuid); } catch (IOException e) { bluetooth_show_message("Bluetooth Error! listenUsingRfcommWithServiceRecord failed. Reason:" + e); running = false; } mmServerSocket = tmp; } public void run() { while (running) { try { socket = mmServerSocket.accept(); } catch (IOException e) { bluetooth_show_message("Bluetooth Error! Accepting a connection failed. Reason:" + e); break; } ... }
public void stop() { try { if (mmServerSocket != null) { mmServerSocket.close(); } } catch (IOException e) { } } }
@Override public void run() { BluetoothSocket socket = null; while (true) { try { socket = mServerSocket.accept(); } catch (IOException e) { e.printStackTrace(); break; } if (socket != null) { readAndWriteData(socket); try { mServerSocket.close(); } catch (IOException e) { e.printStackTrace(); break; } break; } } }
public void run() { try { // Block until client connection established. mBluetoothSocket = btserver.accept(); // Start listening for messages. listenForMessages(); } catch (IOException e) { Log.e(TAG, "Server connection IO Exception", e); } } });
public void cancel() { try { mmServerSocket.close(); mmServerSocket = null; } catch (IOException e) { } }
for (int i = 0; i < 7; i++) { BluetoothServerSocket myServerSocket = mBtAdapter .listenUsingRfcommWithServiceRecord(srcApp, mUuid.get(i)); BluetoothSocket myBSock = myServerSocket.accept(); myServerSocket.close(); // Close the socket now that the connection //has been made //Do stuff with the socket here, like callback to main thread }
BluetoothDevice device = bluetoothadatper.getRemoteDevice(); public class AcceptThread10 extends Thread { private final UUID MY_UUID = UUID.fromString("0125bb20-d629-11e3-9c1a-0800200c9a66"); @Override public void run() { try { BluetoothServerSocket bluesocketserver = bluetoothAdapter.listenUsingRfcommWithServiceRecord(MY_UUID); while (true) { socket = bluesocketserver.accept(); socket12.close(); }
public void cancel() { try { mmServerSocket.close(); } catch (IOException e) { } }
for (int i = 0; i < Connection.MAX_SUPPORTED && maxConnections > 0; i++) { BluetoothServerSocket myServerSocket = mBtAdapter.listenUsingRfcommWithServiceRecord(srcApp, mUuid.get(i)); BluetoothSocket myBSock = myServerSocket.accept(); myServerSocket.close(); // Close the socket now that the // connection has been made. String address = myBSock.getRemoteDevice().getAddress(); mBtSockets.put(address, myBSock); mBtDeviceAddresses.add(address); Thread mBtStreamWatcherThread = new Thread(new BtStreamWatcher(address)); mBtStreamWatcherThread.start(); mBtStreamWatcherThreads.put(address, mBtStreamWatcherThread); maxConnections = maxConnections - 1; if (mCallback != null) { mCallback.incomingConnection(address); } }
BluetoothServerSocket serverSocket = null; BluetoothAdapter bta = BluetoothAdapter.getDefaultAdapter(); try { serverSocket = bta.listenUsingInsecureRfcommWithServiceRecord("BluetoothChatInsecure", UUID.fromString("00001101-0000-1000-8000-00805F9B34FB")); } catch (IOException e) { e.printStackTrace(); } while(!Thread.interrupted()) { try { socket = serverSocket.accept(); if (socket != null) { Log.d("CONNECTED", "Connected bluetooth"); /// do your stuff
/** * Will cancel the listening socket, and cause the thread to finish */ public void cancel() { try { mmServerSocket.close(); } catch (IOException e) { } }
public void run() { Log.d(LOG_TAG, "Running ServerThread"); try { mBluetoothServerSocket.accept(); Log.d(LOG_TAG, "mBluetoothServerSocket.accept() success"); } catch (IOException e1) { Log.e(LOG_TAG, "Error mBluetoothServerSocket.accept()"); e1.printStackTrace(); } }
public void cancel() { try { bluetoothServerSocket.close(); } catch (IOException e) { e.printStackTrace(); } } }