当前位置:编程学习 > C#/ASP.NET >>

C#蓝牙开发问题:由于目标主机坏了,套接字操作失败

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net.Sockets;

using InTheHand.Windows.Forms;
using InTheHand.Net;
using InTheHand.Net.Bluetooth;
using InTheHand.Net.Sockets;

using System.Threading;
using System.Runtime.InteropServices;

using System.Net;
using System.IO;

namespace bluetooth
{
    public partial class Form1 : Form
    {
        BluetoothRadio radio = null;//蓝牙适配器   
        BluetoothAddress sendAddress = null;//发送目的地址  
        string recDir = null;//接受文件存放目录  
        //ObexListener listener = null;//监听器 
        Boolean connection = false;
        BluetoothClient bluetoothClient;
        BluetoothListener bluetoothListener;
      //  Thread listenThread;
        bool isConnected;
  //      NetworkStream peerStream;
        


        public Form1()
        {
            InitializeComponent();
            radio = BluetoothRadio.PrimaryRadio;//获取当前PC的蓝牙适配器  
            CheckForIllegalCrossThreadCalls = false;//不检查跨线程调用  
            if (radio == null)//检查该电脑蓝牙是否可用  
            {
                MessageBox.Show("这个电脑蓝牙不可用!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            recDir = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            SelectBluetoothDeviceDialog dialog = new SelectBluetoothDeviceDialog();
            dialog.ShowRemembered = true;
            dialog.ShowAuthenticated = true;
            dialog.ShowUnknown = true;   
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                sendAddress = dialog.SelectedDevice.DeviceAddress;//获取选择的远程蓝牙地址  
                label1.Text = "地址:" + sendAddress.ToString() + "设备名:" + dialog.SelectedDevice.DeviceName;
                bluetoothClient = new BluetoothClient();
                bluetoothClient.Connect(sendAddress, BluetoothService.PhonebookAccess);//问题在这里
                connection = true;
               // Thread ReceiveThread = new Thread(ReceiveData);
                //ReceiveThread.Start();
            }
        }
        private void Form1_Load(object sender, EventArgs e)
        {
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (connection) { bluetoothClient.Close(); }//; bluetoothListener.Stop(); }
        }
    }
}


蓝牙 c# --------------------编程问答-------------------- google "由于目标主机坏了"

检查下是不是软硬件环境的问题。 --------------------编程问答--------------------
引用 1 楼 caozhy 的回复:
google "由于目标主机坏了"

检查下是不是软硬件环境的问题。


应该不会,我用别的蓝牙驱动就可以连接上IPAD,如果把GUID换成"00001101-0000-1000-8000-00805F9B34FB"
可以连接,但是没有任何功能 --------------------编程问答-------------------- 在线等呀,求大神
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,