本文介绍了蓝牙发送/接收文本,无需在 2 台 Windows 7 计算机上使用 C# 配对的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经读到,在通过蓝牙进行通信之前必须先配对,但我想知道,

I have read that pairing is a must before communicating anything over bluetooth, but I want to know,

我可以创建一个应用程序来读取文本吗?由其他蓝牙应用广播而未配对.

因为我们可以看到设备周围其他蓝牙设备的名称.所以我们不能将我们的蓝牙收音机设置为可以读取任何蓝牙广播文本消息的状态.

Because we can see the names of other bluetooth devices around a device. So can't we set our bluetooth radio to a state that it would read any bluetooth boradcasting text message.

示例:有 createInsecureRfcommSocketToServiceRecord() &listenUsingInsecureRfcommWithServiceRecord() 在 android 中,但在 C# 中没有这样的 windows 吗?

Example: there is createInsecureRfcommSocketToServiceRecord() & listenUsingInsecureRfcommWithServiceRecord() in android but aren't there such in C# for windows?

谢谢

正在创建一个在 Windows 7 PC 上运行的应用程序,该应用程序为点对点文件传输和聊天创建即时蓝牙网络

is creating an application running on windows 7 PCs, which create instant Bluetooth network for peer to peer file transfer and chat

有一群人,每个人的每台计算机上都有这个应用程序,一个人想与其他人共享一个文件(可能是电子书、PDF 或任何东西).他在他的应用程序配置中设置了他的网络网络"(或任何其他名称),其他人也在每个应用程序上设置了相同的名称.最后,每个用户都可以在他们的应用程序显示中看到他们周围的其他蓝牙节点列表,配置为相同的网络名称net".这样每个人都可以将文件发送到同一网络中的选定节点.

There is a group of people, each has this app on each computer, one wants to share a file, (may be an eBook, PDF or anything) with the rest. He sets his network "net" ( or any other name) in his app configuration and others also put that same name on each app. Finally each user can see the list of other Bluetooth nodes around them in their apps display, configured to same network name "net". so each can send files to selected nodes in the same network.

  • 每个用户打开蓝牙无线电,然后在应用中输入所需的网络名称
  • PC 上的每个应用程序将通过临时创建的连接(无需配对或用户参与)迭代地与可访问的蓝牙设备通信,检查它们的网络名称并列出具有相似网络名称的可发现 PC
  • 然后它们将在彼此之间共享这些列表,因此一台 PC 知道同一网络中的计算机,即使它们不在范围内.
  • 通过算法解析的路径将文件从一台计算机发送到一台或多台计算机,甚至发送聊天文本.
  • 所有这些都将通过在每个应用程序之间不时建立的简单临时蓝牙连接来实现,除了网络名称之外,不需要配对或身份验证.(因为我不知道如何使用 C# 创建 Piconets,也不知道如何创建蓝牙路由协议.
  • 未实施其他安全措施.
  • Each user only turns on the Bluetooth radio and then enters a desired Network name in then app
  • Each application on PCs will communicate iteratively to reachable Bluetooth devices, through temporarily created connections (without pairing or user involvement), check their network names and list discoverable PCs with similar network names
  • Then they will share these lists among each other, so one PC knows the computers in their same network even though they are not in range directly.
  • Send files from one computer to one or many computers through a path resolved by an algorithm, even send chat texts.
  • All of this is going to be achieved through simple temporarily Bluetooth connections established between each application time to time, which requires no pairing or authentication, other than the Network Name. ( Because I don't know how to create Piconets using C#, or how to create bluetooth routing protocols.
  • No other security is implemented.

请让我知道任何其他更好的设计或方式.非常感谢您阅读冗长的文字.还包括任何可以帮助我实现上述目标的有用代码.

Please let me know of any other better design or way. Thank you very much for reading the lengthy text. Also include any helpful code which can help me achieve the above.

推荐答案

我每天都会进行数十次未配对的连接...我不知道这个谣言是从哪里来的.:-,)

I make tens of un-paired connections every day... I don't know where this rumour comes from. :-,)

正如您在 Android 上所指出的,默认情况下是经过身份验证的连接——也许这就是谣言开始的地方?正如您所注意到的,即使在那里,也有一些方法可以请求不需要配对"的连接,例如listenUsingInsecureRfcommWithServiceRecord.

As you note on Android the default was for an authenticated connection -- maybe that's where the rumour started from? Even there, as you note, there are ways to request a 'pairing-not-required' connection e.g. listenUsingInsecureRfcommWithServiceRecord.

因此,在 Windows 上的 Microsoft 堆栈中,通过套接字 (winsock) 使用蓝牙 (RFCOMM).默认该连接确实需要身份验证(配对),也不需要加密——事实上,要请求身份验证/加密,必须设置一个套接字选项.与 Widcomm 类似,您在创建连接时指定所需的安全级别,可以是无".在 Bluetopia 上类似,在 Linux 上的 BlueZ 上类似.

So, on the Microsoft stack on Windows one uses Bluetooth (RFCOMM) through a socket (winsock). By default that connection does not require authentication (pairing), nor encryption -- in fact to request auth/enc one must set a socket options. Similarly with Widcomm, you specify when you create the connection what security level you want, and that can be 'None'. Similarly on Bluetopia, similarly on BlueZ on Linux.

因此,如果您使用我的库 32feet.NET,只需使用 BluetoothClient 和 BluetoothListener,不要 设置 cli.Authenticate=true 等 :-)

So if you use my library 32feet.NET, just use BluetoothClient and BluetoothListener and do not set cli.Authenticate=true etc. :-)

你的最终目标是什么?我刚刚意识到您在另一个问题中询问文件传输... :-)

What's your ultimate goal? I've just realised that you were asking about file-transfer in another question... :-)

无论如何传输文本...在服务器端有如下所示的代码:http://32feet.codeplex.com/wikipage?title=Bluetooth%20Server-side 并在客户端上如:http://32feet.codeplex.com/wikipage?title=General%20Bluetooth%20Data%20Connections 不知道你知不知道TextWriter/-Reader.NET 上的子类,无论如何都是一方面:

Anyway for transferring text... On the server-side have code like shown at: http://32feet.codeplex.com/wikipage?title=Bluetooth%20Server-side and on the client like: http://32feet.codeplex.com/wikipage?title=General%20Bluetooth%20Data%20Connections Don't know if you know TextWriter/-Reader sublclasses on .NET, anyway on one side:

....
var wtr = new StreamWriter(peerStream);
wtr.WriteLine("hello");
wtr.Flush();

另一方面:

....
var wtr = new StreamReader(peerStream);
var line = wtr.ReadLine();
MessageBox.Show(line);

BluetoothChat 中的代码几乎可以做类似的事情.

There's code in the BluetoothChat which pretty much does something like that.

艾伦

这篇关于蓝牙发送/接收文本,无需在 2 台 Windows 7 计算机上使用 C# 配对的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 04:44