private void DoStartAdvertising() { Task.Run(() => { _listenerSocket = BluetoothSockets.CreateRfcommSocket(); _listenerSocket.Bind(new BluetoothEndPoint(0, _serviceUuid)); try { _listenerSocket.Listen(1); // TODO: Publish SDP record while (_listenerSocket != null) { var socket = _listenerSocket.Accept(); ConnectionReceived?.Invoke(this, new RfcommConnectionReceivedEventArgs(new System.Net.Sockets.NetworkStream(socket))); } } catch { //TODO: only trap thread cancellation here } }); }
private Task <Stream> OpenStreamAsyncImpl() { return(Task.Run <Stream>(() => { var socket = BluetoothSockets.CreateRfcommSocket(); socket.Connect(new BluetoothEndPoint(this)); return new NetworkStream(socket); })); }
public Stream OpenStream() { var socket = BluetoothSockets.CreateRfcommSocket(); socket.Connect(new BluetoothEndPoint(this)); #if UNITY return(new InTheHand.Networking.Sockets.NetworkStream(socket)); #else return(new NetworkStream(socket)); #endif }