public AcceptThread(boolean secure) { //Tmp变量 BluetoothServerSocket tmp = null; //初始化类型 mSocketType = secure ? "Secure":"Insecure"; // 创建一个服务的Listener try { if (secure) { tmp = mAdapter.listenUsingRfcommWithServiceRecord(NAME_SECURE, MY_UUID_SECURE); } else { tmp = mAdapter.listenUsingInsecureRfcommWithServiceRecord(NAME_INSECURE, MY_UUID_INSECURE); } } catch (IOException e) { Log.e(TAG, "Socket Type: " + mSocketType + "listen() failed", e); } mmServerSocket = tmp; }
public AcceptThread(boolean secure) { BluetoothServerSocket tmp = null; mSocketType = secure ? "Secure" : "Insecure"; // Create a new listening server socket try { if (secure) { tmp = mAdapter.listenUsingRfcommWithServiceRecord(NAME_SECURE, MY_UUID_SECURE); } else { tmp = mAdapter.listenUsingInsecureRfcommWithServiceRecord(NAME_INSECURE, MY_UUID_INSECURE); } } catch (IOException e) { MyLog.e(TAG, "Listen to " + mSocketType + " socket type failed. More: ", e); } mmServerSocket = tmp; }
public AcceptThread(boolean secure) { BluetoothServerSocket tmp = null; mSocketType = secure ? "Secure" : "Insecure"; // Create a new listening server socket try { if (secure) { tmp = mAdapter.listenUsingRfcommWithServiceRecord(NAME_SECURE, MY_UUID_SECURE); } else { tmp = mAdapter.listenUsingInsecureRfcommWithServiceRecord( NAME_INSECURE, MY_UUID_INSECURE); } } catch (IOException e) { Log.e(TAG, "Socket Type: " + mSocketType + "listen() failed", e); } mmServerSocket = tmp; mState = STATE_LISTEN; }
/** * Sets new server socket. */ public void setNewServerSocket() { BluetoothServerSocket tmp = null; try { if(mProtocolVer == 2) tmp = mAdapter.listenUsingRfcommWithServiceRecord( NAME_PEN, NeoOne_UUID ); else tmp = mAdapter.listenUsingInsecureRfcommWithServiceRecord( NAME_PEN, NeoOne_UUID ); NLog.d( "[BTAdt] ListenThread new BT ServerSocket assigned" ); } catch ( IOException e ) { NLog.e( "[BTAdt] ListenThread new BT ServerSocket assign fail", e ); } mmServerSocket = tmp; }
public AcceptThread(boolean secure) { BluetoothServerSocket tmp = null; mSocketType = secure ? "Secure" : "Insecure"; // Create a new listening server socket try { if (secure) { tmp = mAdapter.listenUsingRfcommWithServiceRecord(NAME_SECURE, MY_UUID_SECURE); } else { tmp = mAdapter.listenUsingInsecureRfcommWithServiceRecord( NAME_INSECURE, MY_UUID_INSECURE); } } catch (IOException e) { Log.e(TAG, "Socket Type: " + mSocketType + "listen() failed", e); } mmServerSocket = tmp; }
@Override public KeyAgreementListener createKeyAgreementListener(byte[] commitment) { if (!isRunning()) return null; // There's no point listening if we can't discover our own address String address = AndroidUtils.getBluetoothAddress(appContext, adapter); if (address.isEmpty()) return null; // No truncation necessary because COMMIT_LENGTH = 16 UUID uuid = UUID.nameUUIDFromBytes(commitment); if (LOG.isLoggable(INFO)) LOG.info("Key agreement UUID " + uuid); // Bind a server socket for receiving invitation connections BluetoothServerSocket ss; try { ss = adapter.listenUsingInsecureRfcommWithServiceRecord( "RFCOMM", uuid); } catch (IOException e) { if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e); return null; } BdfList descriptor = new BdfList(); descriptor.add(TRANSPORT_ID_BLUETOOTH); descriptor.add(StringUtils.macToBytes(address)); return new BluetoothKeyAgreementListener(descriptor, ss); }
public AcceptThread(boolean secure) { BluetoothServerSocket tmp = null; mSocketType = secure ? "Secure" : "Insecure"; // Create a new listening server socket try { if (secure) { tmp = mAdapter.listenUsingRfcommWithServiceRecord(NAME_SECURE, MY_UUID_SECURE); } else { tmp = mAdapter.listenUsingInsecureRfcommWithServiceRecord(NAME_INSECURE, MY_UUID_INSECURE); } } catch (IOException | NullPointerException e) { Log.e(TAG, "Socket Type: " + mSocketType + "listen() failed", e); } mmServerSocket = tmp; mState = STATE_LISTEN; }
public ServerThread(BluetoothAdapter adapter, Handler handler, boolean secure) { this.handler = handler; BluetoothServerSocket tempSocket = null; try { if (secure) tempSocket = adapter.listenUsingRfcommWithServiceRecord(Constants.NAME, UUID.fromString(Constants.UUID_STRING)); else tempSocket = adapter.listenUsingInsecureRfcommWithServiceRecord(Constants.NAME, UUID.fromString(Constants.UUID_STRING)); } catch (IOException ioe) { Log.e(TAG, ioe.toString()); } serverSocket = tempSocket; }
public AcceptThread(boolean secure) { BluetoothServerSocket tmp = null; mSocketType = secure ? "Secure":"Insecure"; // Create a new listening server socket try { if (secure) { tmp = mAdapter.listenUsingRfcommWithServiceRecord(NAME_SECURE, MY_UUID_SECURE); } else { tmp = mAdapter.listenUsingInsecureRfcommWithServiceRecord( NAME_INSECURE, MY_UUID_INSECURE); } } catch (IOException e) { Log.e(TAG, "Socket Type: " + mSocketType + "listen() failed", e); } mmServerSocket = tmp; }
/** * コンストラクタ * @param secure セキュア接続を待機するならtrue */ public ListeningThread(final boolean secure) { super("ListeningThread:" + mName); // Create a new listening server socket BluetoothServerSocket tmp = null; try { if (secure) { // セキュアな接続を行うためのBluetoothServerSocketを生成 tmp = mAdapter.listenUsingRfcommWithServiceRecord(mName, mSecureProfileUUID); } else { tmp = mAdapter.listenUsingInsecureRfcommWithServiceRecord(mName, mInSecureProfileUUID); } } catch (final IOException e) { Log.w(TAG, e); } mmServerSocket = tmp; }
public AcceptThread(boolean secure) { BluetoothServerSocket tmp = null; mSocketType = secure ? "Secure":"Insecure"; // Create a new listening server socket try { if (secure) { tmp = mAdapter.listenUsingRfcommWithServiceRecord(NAME_SECURE, MY_UUID_SECURE); } else { tmp = mAdapter.listenUsingInsecureRfcommWithServiceRecord( NAME_INSECURE, MY_UUID_INSECURE); } } catch (IOException e) { } mmServerSocket = tmp; }
public AcceptThread(boolean isAndroid, boolean secure) { BluetoothServerSocket tmp = null; try { if (secure) { if (isAndroid) tmp = mAdapter.listenUsingRfcommWithServiceRecord(NAME_SECURE, UUID_ANDROID_DEVICE); else tmp = mAdapter.listenUsingRfcommWithServiceRecord(NAME_SECURE, UUID_OTHER_DEVICE); } else { if (isAndroid) tmp = mAdapter.listenUsingInsecureRfcommWithServiceRecord(NAME_SECURE, UUID_ANDROID_DEVICE); else tmp = mAdapter.listenUsingInsecureRfcommWithServiceRecord(NAME_SECURE, UUID_OTHER_DEVICE); } } catch (IOException e) { e.printStackTrace(); } mmServerSocket = tmp; }
public void setNewServerSocket() { BluetoothServerSocket tmp = null; try { tmp = mAdapter.listenUsingInsecureRfcommWithServiceRecord( NAME_PEN, NeoOne_UUID ); //tmp = mAdapter.listenUsingRfcommWithServiceRecord( NAME_PEN, NeoOne_UUID ); NLog.d( "[BTAdt] ListenThread new BT ServerSocket assigned" ); } catch ( IOException e ) { NLog.e( "[BTAdt] ListenThread new BT ServerSocket assign fail", e ); } mmServerSocket = tmp; }
AcceptThread(boolean secure, int timeout) { BluetoothServerSocket tmp = null; this.mSecure = secure; this.mTimeout = timeout; // Create a new listening server socket try { if (secure) { tmp = mAdapter.listenUsingRfcommWithServiceRecord(NAME_SECURE, MY_UUID_SECURE); } else { tmp = mAdapter.listenUsingInsecureRfcommWithServiceRecord(NAME_INSECURE, MY_UUID_INSECURE); } } catch (IOException e) { Log.e(TAG, "Socket Type: " + getSocketType(secure) + "listen() failed", e); } mmServerSocket = tmp; }
/** * Initialize the thread. * * @param adapter The bluetooth adapter */ public AcceptThread(BluetoothAdapter adapter, OnSocketEstablishedListener onSocketEstablishedListener, OnStateChangedListener stateListener, OnErrorListener errorListener) { super(TAG); this.onSocketEstablishedListener = onSocketEstablishedListener; this.stateListener = stateListener; this.errorListener = errorListener; BluetoothServerSocket tmp = null; try { tmp = adapter.listenUsingRfcommWithServiceRecord( Config.BLUETOOTH_SERVICE_NAME, UUID.fromString(Config.BLUETOOTH_UUID_STR)); } catch (IOException e) { Log.e(TAG, "Error:", e); errorListener.onError(OnErrorListener.ERR_SOCKET_CREATE, e); } serverSocket = tmp; }
/********************************************************************** * Name: AcceptThread * Description: Constructor for the class. Attempts to instantiate the * ServerSocket based on the passed parameter * * @param secure boolean indicating the type of connection to * listen for **********************************************************************/ public AcceptThread(boolean secure) { BluetoothServerSocket tmp = null; mSocketType = secure ? "Secure" : "Insecure"; // Create a new listening server socket try { if (secure) tmp = btAdapter.listenUsingRfcommWithServiceRecord( NAME_SECURE, UUID_SECURE); else tmp = btAdapter.listenUsingInsecureRfcommWithServiceRecord( NAME_INSECURE, UUID_INSECURE); } catch (IOException e) { e.printStackTrace(); } mmServerSocket = tmp; }
public AcceptThread(BluetoothChannel channel, BluetoothAdapter bluetoothAdapter) { this.mChannel = channel; bluetoothAdapter.cancelDiscovery(); BluetoothServerSocket tmp = null; try { tmp = bluetoothAdapter.listenUsingRfcommWithServiceRecord("SysplaceApp", BluetoothChannel.MY_UUID); } catch (IOException e) { Log.e(TAG, "Could not open Server Socket"); } mmServerSocket = tmp; }
public AcceptThread(boolean secure) { BluetoothServerSocket tmp = null; mSocketType = secure ? "Secure":"Insecure"; // Create a new listening server socket try { if (secure) { tmp = mAdapter.listenUsingRfcommWithServiceRecord(NAME_SECURE, MY_UUID_SECURE); } else { tmp = mAdapter.listenUsingInsecureRfcommWithServiceRecord(NAME_INSECURE, MY_UUID_INSECURE); } } catch (IOException e) { Log.e(TAG, "Socket Type: " + mSocketType + "listen() failed", e); } mmServerSocket = tmp; }
public AcceptThread(boolean secure) { BluetoothServerSocket tmp = null; //mSocketType = secure ? "Secure" : "Insecure"; mSocketType = "Insecure"; // Create a new listening server socket try { if (secure) { tmp = mAdapter.listenUsingRfcommWithServiceRecord(NAME_SECURE, MY_UUID_SECURE); } else { tmp = mAdapter.listenUsingInsecureRfcommWithServiceRecord( NAME_INSECURE, MY_UUID_INSECURE); } } catch (IOException e) { Log.e(TAG, "Socket Type: " + mSocketType + "listen() failed", e); } mmServerSocket = tmp; }
public BluetoothServerTask(Context context) throws NoBluetoothException { Log.i("BluetoothServerTask", "Created"); mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (mBluetoothAdapter == null) { // Device does not support Bluetooth throw new NoBluetoothException(); } this.context = context; Log.i("BluetoothServerTask", "Got adapter"); // Use a temporary object that is later assigned to mmServerSocket, // because mmServerSocket is final BluetoothServerSocket tmp = null; try { // MY_UUID is the app's UUID string, also used by the client code tmp = mBluetoothAdapter.listenUsingInsecureRfcommWithServiceRecord( Remote.BLUETOOTH_NAME, Remote.BLUETOOTH_UUID); Log.i("BluetoothServerTask", "Created insecure server socket"); } catch (IOException e) { throw new NoBluetoothException(); } mmServerSocket = tmp; }
public AcceptThread(boolean secure) { _socketType = secure ? "Secure" : "Insecure"; // Create a new listening server socket BluetoothServerSocket serverSocket = null; try { if (secure) { if (_debug) Log.d(TAG, "AcceptThread: started listening secure, uuid = " + _secureUuid + ", spd name = " + _secureSPDName); serverSocket = _adapter.listenUsingRfcommWithServiceRecord(_secureSPDName, _secureUuid); } else { if (_debug) Log.d(TAG, "AcceptThread: started listening insecure, uuid = " + _insecureUuid + ", spd name = " + _insecureSPDName); serverSocket = _adapter.listenUsingInsecureRfcommWithServiceRecord(_insecureSPDName, _insecureUuid); } } catch (IOException e) { Log.e(TAG, "AcceptThread: listen failed"); e.printStackTrace(); } _serverSocket = serverSocket; _isListening = true; }
public AcceptThread(boolean secure) { BluetoothServerSocket tmp = null; mSocketType = secure ? "Secure" : "Insecure"; // Create a new listening server socket try { if (secure) { tmp = mAdapter.listenUsingRfcommWithServiceRecord(NAME_SECURE, MY_UUID_SECURE); } else { tmp = mAdapter.listenUsingInsecureRfcommWithServiceRecord( NAME_INSECURE, BASKET_UUID_INSECURE); } } catch (IOException e) { Log.e(TAG, "Socket Type: " + mSocketType + "listen() failed", e); } mmServerSocket = tmp; }
public AcceptThread(boolean secure) { BluetoothServerSocket tmp = null; mSocketType = secure ? "Secure" : "Insecure"; // Create a new listening server socket try { // if (secure) { // tmp = mAdapter.listenUsingRfcommWithServiceRecord(NAME_SECURE, // MY_UUID_SECURE); // } else { tmp = mAdapter.listenUsingInsecureRfcommWithServiceRecord( NAME_INSECURE, MY_UUID_INSECURE); // } } catch (IOException e) { Log.e(TAG, "Socket Type: " + mSocketType + "listen() failed", e); } mmServerSocket = tmp; }
public AcceptThread(boolean isAndroid, boolean secure) { BluetoothServerSocket tmp = null; // Create a new listening server socket try { if (secure) { if(isAndroid) tmp = mAdapter.listenUsingRfcommWithServiceRecord(NAME_SECURE, UUID_ANDROID_DEVICE); else tmp = mAdapter.listenUsingRfcommWithServiceRecord(NAME_SECURE, UUID_OTHER_DEVICE); } else { if(isAndroid) tmp = mAdapter.listenUsingInsecureRfcommWithServiceRecord(NAME_SECURE, UUID_ANDROID_DEVICE); else tmp = mAdapter.listenUsingInsecureRfcommWithServiceRecord(NAME_SECURE, UUID_OTHER_DEVICE); } } catch (IOException e) { } mmServerSocket = tmp; }
public ListernerBluetoothThread(final ProxyManager proxyManager) { final BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); BluetoothServerSocket tmp = null; try { // MY_UUID is the app's UUID string, also used by the client code tmp = mBluetoothAdapter.listenUsingRfcommWithServiceRecord(NAME_SECURE, proxyManager .getUuidSecure()); } catch (Exception ex) { Log.e(TAG, "Fail", ex); } mmServerSocket = tmp; this.proxyManager = proxyManager; }
public AcceptThread() { BluetoothServerSocket tmp = null; isAccepting = true; try { tmp = mBluetoothAdapter. listenUsingRfcommWithServiceRecord( mChatRoomName, java.util.UUID.fromString(MainActivity.UUID) ); } catch (IOException e) { System.err.println("Failed to set up Accept Thread"); System.err.println(e.toString()); } mmServerSocket = tmp; }
@Override public void run() { try { Log.d("DEBUG", "Listening with uuid: " + Main.uuids[iterator].toString()); BluetoothServerSocket serverSocket = adapter.listenUsingRfcommWithServiceRecord(Integer.toString(iterator), Main.uuids[iterator]); Log.d("DEBUG", "Accepting..."); socket = serverSocket.accept(); Log.d("DEBUG", "Connected. Closing server socket."); serverSocket.close(); //TODO: (Accept) Pass the socket to another thread for read/write management. Manage thread = new Manage(socket); manageThreads.add(thread); executor.execute(thread); /*Log.d("DEBUG", "Not doing anything. Closing connected socket."); socket.close();*/ } catch (IOException e) { Log.d("DEBUG", "Exception", e); } }
@Override protected BluetoothSocket doInBackground(BluetoothAdapter... bt) { BluetoothSocket mSocket = null; Log.d(TAG, "Starting doinbackground"); try { Log.d(TAG, bt[0].getName()); BluetoothServerSocket server = bt[0].listenUsingInsecureRfcommWithServiceRecord(name, uuid); Log.d(TAG, "Received serversocket from UUID " + uuid + ", now accepting"); mSocket = server.accept(); Log.d(TAG, "Received socket, closing server"); server.close(); } catch (IOException e) { e.printStackTrace(); Log.d("AsyncTask", "Unable to get bluetooth socket"); } return mSocket; }
public AcceptThread() { // Use a temporary object that is later assigned to mmServerSocket, // because mmServerSocket is final BluetoothServerSocket tmp = null; try { // MY_UUID is the app's UUID string, also used by the client code tmp = bluetoothAdapter.listenUsingRfcommWithServiceRecord(SERVER_NAME, SERVER_UUID); } catch (IOException e) { } mmServerSocket = tmp; if(bluetoothHandler != null) { bluetoothHandler .obtainMessage(BluetoothHandler.MESSAGE_WAIT_FOR_CONNECTION) .sendToTarget(); } }