[XAP] Bluetooth Chat (Based on DllImport)
I've spent some time to investigate about Bluetooth status on Windows Phone 7 using DllImport approach for some applications I'm developing.
This is a simple chat app between a WP7 device and a counterpart (i.e a PC, another WP7 device, ...) using bluetooth serial communication.
I tried this app by connect my WP7 device to a PC and to another WP7 device.
It permits to exchange text messages between each side, like a classic chat program.
Tested WP7 devices (LG Optimus 7, Nokia Lumia 800 and HTC Mondrian) are all dev-unloked.
Application main page have the following possible actions:
- Connect to a remote device (if selected it will open a new page where to choose previously paired device or to find new one)
- Act as server (if selected it creates a new serial connection using device port 10 and it will listen for new incoming connection from remote device)
- Disconnect (to stop a connection towards remote device, or to stop server mode)
- Send (it will be enable only when connected as client or server. If selected will send your message to counterpart).
- Settings (if selected it will open a new page where to set application option)
Note: at the moment there is no automatic notification about connection down event.
Thanks to Heathcliff74 and fiinix for their works on WP7
Note: This is a simple project to verify if all core procedures (connection open and close, send and receive messages, ...) are working in the right way.
P.S 1: if you eant to test the app between WP7 device and a PC use this procedure:
- Start Bluetooth on WP7 device
- From PC search for WP7 device and pair it
- Start BlueChat on WP7 device in server mode
- From PC search for Device exported services: you'd see a SPP (AUX3) option, if yes select it and then PC will create a new local COM Port
- Open a Putty using this COM Port and start to write to WP7 device!
P.S. 2: if you eant to communicate between 2 WP7 devices:
- On device 1 go to bluetooth settings page and activate it (this is important because only when we are in this page the device is discoverable from outside)
- On device 2 open BlueChat and choose "Connect" button. In the "Connect To" page choose "Search" option and in some seconds you'd see device 1
- Select device 1 form the list. Before select "Done" button, on device 2 open BlueChat and starts it in Server mode
- Then on device 1 select "Done" button and the devices will be connected
- Now you can exchange data between the two devices