复制代码 代码如下:
using inthehand.net.sockets;
using system.threading;
public mainwindow()
{
initializecomponent();
listenthread = new thread(receivedata);
listenthread.start();
}
private void receivedata()
{
try
{
guid mguid = guid.parse("00001101-0000-1000-8000-00805f9b34fb");
bluetoothlistener = new bluetoothlistener(mguid);
bluetoothlistener.start();
bluetoothclient = bluetoothlistener.acceptbluetoothclient();
isconnected = true;
}
catch (exception)
{
isconnected = false;
}
while (isconnected)
{
string receive = string.empty;
if (bluetoothclient == null)
{
break;
}
try
{
peerstream = bluetoothclient.getstream();
byte[] buffer = new byte[6];
peerstream.read(buffer, 0, 6);
receive = encoding.utf8.getstring(buffer).tostring();
}
catch (system.exception)
{
}
thread.sleep(100);
}
}
bluetoothclient bluetoothclient;
bluetoothlistener bluetoothlistener;
thread listenthread;
bool isconnected;
备注:发现用两个手机跟电脑配对成功后,两个手机同时连上pc端软件,一起发数据的话,pc端谁的也不接,暂时不下结论。
您可能感兴趣的文章:
如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!
网友评论