开发者

Bluetooth send/receive text without pairing using C# on 2 Windows 7 Computers

开发者 https://www.devze.com 2023-03-27 09:56 出处:网络
I have read that pairing is a must before communicating anything over bluetooth, but I want to know, Can I create an application which would read a text which is

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

Can I create an application which would read a text which is broadcasted by another bluetooth App without being paired.

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.

Example: there is createInsecureRfcommSocketToServiceRecord() & listenUsingInsecureRfcommWithServiceRecord() in andr开发者_如何学Coid but aren't there such in C# for windows?

Thanks


My Ultimate Goal :-)

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

Scenario

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.

Design

  • 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. :-,)

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.

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.

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

Some code examples

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

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();

and on the other:

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

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

Alan

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号