Ajuda: programa em C# ou C++ para comunicar por Bluetooth

Boa noite pessoal.
Preciso fazer um programa em C# ou C++ para comunicar via Bluetooth entre dois pcs para a disciplina de redes. O ideal, disse o Professor, seria um pc enviar uma imagem da camera para o outro pc e o outro faria o mesmo.
Alguém sabe como posso fazer utilizando o Visual Studio?
Alguém tem algo parecido, um toturial ou video a explicar como fazer?
Acho que preciso instalar librarias para isso.

Cumprimentos.
 
Boa noite pessoal.
Preciso fazer um programa em C# ou C++ para comunicar via Bluetooth entre dois pcs para a disciplina de redes. O ideal, disse o Professor, seria um pc enviar uma imagem da camera para o outro pc e o outro faria o mesmo.
Alguém sabe como posso fazer utilizando o Visual Studio?
Alguém tem algo parecido, um toturial ou video a explicar como fazer?
Acho que preciso instalar librarias para isso.

Cumprimentos.

Eu não testei este artigo mas tens aqui : http://www.c-sharpcorner.com/uploadfile/krishnasarala/transfer-files-over-bluetooth-devices

Se não te servir fazes uma pesquisa por C# send files via bluetooth e vai te aparecer um monte de informação de librarias etc para fazeres isso.
 
Peço imensa desculpa pela demora porque estive em exames, pelo que vou começar agora a fazer o trabalho prático.

Este consiste em fazer em c# ou c++ um programa que comunique por Bluetooth, como já havia dito.
Este programa terá de ser capaz de detectar, por Bluetooth, o pc do parceiro de grupo e ir buscar numa pasta definida um ficheiro do tipo imagem.
Pode ser só um pc a fazer isso, o outro deverá conter a imagem numa directoria.

Tenho que ter isto a funcionar até ao dia 1 de Janeiro, pelo que aceito sugestões.

A minha ideia é: eu criar o programa que vai detectar o pc do meu parceiro por Bluetooth. Este aceita a comunicação (ou tenho comunicação directa, pois pode ser das duas formas) que tem uma imagem numa pasta no directório c:\imagem\ , por ex.
Depois o meu pc tem que fazer o "download" da imagem e eu ver a imagem no meu pc.

Preciso, por parte da comunidade, sugestões. Tenho o visual studio 2015 instalado que utilizo para as aulas de c#. Ja instalei as bibliotecas necessárias.

Alguém tem algum tutorial deste tipo ou sabe como fazer?

Agradeço a vossa ajuda.

Cumprimentos
 
Boas. Infelizmente ainda nao consegui fazer grande coisa, nem eu nem o meu parceiro de grupo. Temos andado a fazer exemplos pelo youtube e forums mas nada parece resultar. Vamos tentar pela dica que me deixaste.
Amanha posto o resultado. Obrigadão e bom ano de 2017.
 
Boas pessoal até agora fiz isto no visual studio 2013 e usei o 32 feet, mas o programa detecta outros aparelhos mas não emparelha da-me erro, aqui vai o código em baixo vejam se me podem ajudar;


Código:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;
using InTheHand;
using InTheHand.Net.Bluetooth;
using InTheHand.Net.Ports;
using InTheHand.Net.Sockets;
using System.IO;



namespace redes_catia_coutinho
{
    public partial class Form1 : Form
    {
        List<string> items;
        public Form1()
        {
            items = new List<string>();
            InitializeComponent();
        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
           
        }

        private void bGo_Click(object sender, EventArgs e)
        {
            if (serverStarted)
            {
                updateUI("server already started!");
                return;
            }

            if (rbClient.Checked)
            {
                startScan();
            }
            else
            {
                connectAsServer();
            }
        }

        private void startScan()
        {
            listBox1.DataSource = null;
            listBox1.Items.Clear();
            items.Clear();
            Thread bluetoothScanThread = new Thread(new ThreadStart(scan));
            bluetoothScanThread.Start();

        }

        BluetoothDeviceInfo[] devices;
        private void scan()
        {
           
            updateUI("Starting Scan..");
            BluetoothClient client = new BluetoothClient();
            devices = client.DiscoverDevicesInRange();
            updateUI("Scan complete");
            updateUI(devices.Length.ToString() + "Device discovered");
            foreach (BluetoothDeviceInfo d in devices)
            {
                items.Add(d.DeviceName);
            }

            updateDeviceList();

        }

        private void connectAsServer()
        {
            Thread bluetoothServerThread = new Thread(new ThreadStart(ServerConnectThread));
            bluetoothServerThread.Start();
        }

        //private void ServerConnectThread()
        //{
        //    throw new NotImplementedException();
        //}

        private void connectAsClient()
        {
            throw new NotImplementedException();
        }
        Guid mUUID = new Guid("00001101-0000-1000-0000-00805F9834FB");
        bool serverStarted = false;
        public void ServerConnectThread()
        {
            serverStarted = true;
            updateUI("Server started, waiting for clients");
            BluetoothListener blueListener = new BluetoothListener(mUUID);
            blueListener.Start();
            BluetoothClient conn = blueListener.AcceptBluetoothClient();
            updateUI("Client has connected");

            Stream mStream = conn.GetStream();
            while (true)
            {
                try
                {
                    //handle server connection
                    byte[] received = new byte[1024];
                    mStream.Read(received, 0, received.Length);
                    updateUI("Received: " + Encoding.ASCII.GetString(received));
                    byte[] sent = Encoding.ASCII.GetBytes("Hello World");
                    mStream.Write(sent, 0, sent.Length);
                }
                catch (IOException exception)
                {
                    updateUI("Client has disconnected!!!!");
                }

            }

        }
        private void updateUI(string message)
        {
            Func<int> del = delegate()
        {
            tbOutput.AppendText(message + System.Environment.NewLine);
            return 0;
        };
            Invoke(del);
        }

        private void updateDeviceList()
        {
            Func<int> del = delegate()
            {
                listBox1.DataSource = items;
                return 0;
            };
            Invoke(del);
        }


        BluetoothDeviceInfo deviceInfo;
        private void listBox1_DoubleClick(object sender, EventArgs e)
        {
            deviceInfo = devices.ElementAt(listBox1.SelectedIndex);
            updateUI(deviceInfo.DeviceName + "was selected, attempting connect");

            if (pairDevice())
            {
                updateUI("Device paired..");
                updateUI("Starting connect thread");
                Thread bluetoothClientThread = new Thread(new ThreadStart(ClientConnectThread));
                bluetoothClientThread.Start();


            }
            else
            {
                updateUI("Pair Failed");
            }

        }

        private void ClientConnectThread()
        {
            BluetoothClient client = new BluetoothClient();
            updateUI("attempting connect");
            client.BeginConnect(deviceInfo.DeviceAddress, mUUID, this.BluetoothClientConnectCallback, client);


        }

        void BluetoothClientConnectCallback(IAsyncResult result)
        {
            BluetoothClient client = (BluetoothClient)result.AsyncState;
            client.EndConnect(result);

            Stream stream = client.GetStream();
            stream.ReadTimeout = 1000;

            while (true)
            {
                while (!ready) ;

                stream.Write(message, 0, message.Length);
            }
        }

        string myPin = "1234";
        private bool pairDevice()
        {
            if (!deviceInfo.Authenticated)
            {
                if (!BluetoothSecurity.PairRequest(deviceInfo.DeviceAddress, myPin))
                {
                    return false;

                }
            }
            return true;
        }

       
        private void Form1_Load(object sender, EventArgs e)
        {

        }


        bool ready = false;
        byte[] message;
        private void tbText_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
            {
                message = Encoding.ASCII.GetBytes(tbText.Text);
                ready = true;
                tbText.Clear();
            }
        }

        private void rbClient_CheckedChanged(object sender, EventArgs e)
        {

        }
    }
}
 
Back
Topo