Client-side Bluetooth reception (C #) Knowledge Summary

Source: Internet
Author: User

There is a lot of information on the Internet and it is very easy to use when receiving Bluetooth, but I think it is necessary to summarize this knowledge. Bluetooth development requires a third-party library, InTheHand. net. personal. dll. The two key classes are javasthclient and javasthlistener. First, enable a subthread to continuously receive data. It is easy to use and directly run the Code: Copy codeThe Code is as follows: using InTheHand. Net. Sockets;
Using System. Threading;
Public MainWindow ()
{
InitializeComponent ();
ListenThread = new Thread (ReceiveData );
ListenThread. Start ();
}
Private void ReceiveData ()
{
Try
{
Guid mGUID = Guid. Parse ("20171101-0000-1000-8000-00805f9b34fb ");
Descrithlistener = new descrithlistener (mGUID );
Listen thlistener. Start ();
Descrithclient = descrithlistener. acceptblustmthclient ();
IsConnected = true;
}
Catch (Exception)
{
IsConnected = false;
}
While (isConnected)
{
String receive = string. Empty;
If (then thclient = null)
{
Break;
}
Try
{
PeerStream = descrithclient. GetStream ();
Byte [] buffer = new byte [6];
PeerStream. Read (buffer, 0, 6 );
Receive = Encoding. UTF8.GetString (buffer). ToString ();
}
Catch (System. Exception)
{
}
Thread. Sleep (100 );
}
}
BluetoothClient extends thclient;
Descrithlistener extends thlistener;
Thread listenThread;
Bool isConnected;

Note: after finding that two mobile phones are successfully paired with the computer, the two mobile phones are connected to the PC software at the same time. If data is sent together, no one on the PC will be able to answer this question.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.