StreamSocket socket = null;
DataWriter datawriter = null;
DataReader dataReader = null;
socket = new StreamSocket();
datawriter = new DataWriter(socket.OutputStream);
dataReader = new DataReader(socket.InputStream);
public async Task<byte[]> sendreceive(byte[] bytes)
{
try
{
datawriter.WriteBytes(bytes);
await datawriter.StoreAsync(); //Exception here
}
catch (Exception ex)
{
throw ex;
}
}
//connect the socket
socket = new StreamSocket();
await socket.ConnectAsync(
rfcommService.ConnectionHostName,
rfcommService.ConnectionServiceName,
SocketProtectionLevel.BluetoothEncryptionAllowNullAuthentication);
The exception comes is: A first chance exception of type 'System.InvalidOperationException' occurred in filename.exe
Additional information: A method was called at an unexpected time. (Exception from HRESULT: 0x8000000E)
Please help if anyone can.
User contributions licensed under CC BY-SA 3.0