当前位置: 首页>>代码示例>>C#>>正文


C# BluetoothClient.GetStream方法代码示例

本文整理汇总了C#中InTheHand.Net.Sockets.BluetoothClient.GetStream方法的典型用法代码示例。如果您正苦于以下问题:C# BluetoothClient.GetStream方法的具体用法?C# BluetoothClient.GetStream怎么用?C# BluetoothClient.GetStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在InTheHand.Net.Sockets.BluetoothClient的用法示例。


在下文中一共展示了BluetoothClient.GetStream方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetImages

        public static void GetImages(BluetoothEndPoint endpoint, Color tagColor)
        {
            InTheHand.Net.Sockets.BluetoothClient btc = new InTheHand.Net.Sockets.BluetoothClient();
            btc.Connect(endpoint);
            var nws = btc.GetStream();
            byte[] emptySize = BitConverter.GetBytes(0); //
            if (BitConverter.IsLittleEndian) Array.Reverse(emptySize); // redundant but usefull in case the number changes later..
            nws.Write(emptySize, 0, emptySize.Length); // write image size
            int imgCount = GetImgSize(nws);
            nws = btc.GetStream();
            for (int i = 0; i < imgCount; i++)
            {
                MemoryStream ms = new MemoryStream();
                int size = GetImgSize(nws);
                if (size == 0) continue;
                byte[] buffer = new byte[size];
                int read = 0;

                while ((read = nws.Read(buffer, 0, buffer.Length)) != 0)
                {
                    ms.Write(buffer, 0, read);
                }
                SurfaceWindow1.AddImage(System.Drawing.Image.FromStream(ms), tagColor);
            }
        }
开发者ID:EmilBechMadsen,项目名称:AEBM-ITU-PSCT-2013,代码行数:25,代码来源:BluetoothHandler.cs

示例2: readInfoClient

        public void readInfoClient()
        {
            bluetoothClient = bluetoothListener.AcceptBluetoothClient();
                    Console.WriteLine("Cliente Conectado!");

            Stream stream = bluetoothClient.GetStream();

            while (bluetoothClient.Connected)
                    {
                        try
                        {
                            byte[] byteReceived = new byte[1024];
                                int read = stream.Read(byteReceived, 0, byteReceived.Length);
                                if (read > 0)
                                {
                                    Console.WriteLine("Messagem Recebida: " + Encoding.ASCII.GetString(byteReceived) + System.Environment.NewLine);
                                }
                                stream.Flush();
                        }
                        catch (Exception e)
                        {
                                Console.WriteLine("Erro: " + e.ToString());
                        }
                    }
                    stream.Close();
        }
开发者ID:lucasmlima08,项目名称:ConnectionBluetoothDesktop,代码行数:26,代码来源:Server.cs

示例3: connectToDeviceWithoutPairing

        /// <summary>
        /// Attempt to connect to the BluetoothDevice, without trying to pair first.
        /// </summary>
        /// <param name="device"></param>
        /// <returns></returns>
        public static async Task<Boolean> connectToDeviceWithoutPairing(BluetoothDevice device) {
            BluetoothEndPoint endPoint = new BluetoothEndPoint(device.btDeviceInfo.DeviceAddress, BluetoothService.SerialPort);
            BluetoothClient client = new BluetoothClient();
            if (!device.Authenticated) {
                return false;
            }
            else {
                try {
                    client.Connect(endPoint);

                    if (devicesStreams.Keys.Contains(device)) {
                        devicesStreams.Remove(device);
                    }
                    devicesStreams.Add(device, client.GetStream());

                    if (devicesClients.Keys.Contains(device)) {
                        devicesClients.Remove(device);
                    }
                    devicesClients.Add(device, client);
                }
                catch (Exception ex) {
                    //System.Console.Write("Could not connect to device: " + device.DeviceName + " " + device.DeviceAddress);
                    return false;
                }
                return true;
            }
        }
开发者ID:donnaknew,项目名称:programmingProject,代码行数:32,代码来源:Bluetooth.cs

示例4: ServerConnectThread

        public void ServerConnectThread()
        {
            updateUI("Server started, waiting for client");
            bluetoothListener = new BluetoothListener(mUUID);
            bluetoothListener.Start();
            conn = bluetoothListener.AcceptBluetoothClient();

            updateUI("Client has connected");
            connected = true;

            //Stream mStream = conn.GetStream();
            mStream = conn.GetStream();

            while (connected)
            {
                try
                {
                    byte[] received = new byte[1024];
                    mStream.Read(received, 0, received.Length);
                    string receivedString = Encoding.ASCII.GetString(received);
                    //updateUI("Received: " + receivedString);
                    handleBluetoothInput(receivedString);
                    //byte[] send = Encoding.ASCII.GetBytes("Hello world");
                    //mStream.Write(send, 0, send.Length);
                }
                catch (IOException e)
                {
                    connected = false;
                    updateUI("Client disconnected");
                    disconnectBluetooth();
                }
            }
        }
开发者ID:CGHill,项目名称:Random-Projects,代码行数:33,代码来源:Form1.cs

示例5: OpenAsync

 public Task OpenAsync()
 {
     return Task.Run( () =>
     {
         _tokenSource = new CancellationTokenSource();
         _client = new BluetoothClient();
         _client.Connect( _deviceInfo.DeviceAddress, BluetoothService.SerialPort );
         _networkStream = _client.GetStream();
         Task.Factory.StartNew( CheckForData, _tokenSource.Token, TaskCreationOptions.LongRunning,
             TaskScheduler.Default );
     } );
 }
开发者ID:mubold,项目名称:PebbleSharp,代码行数:12,代码来源:PebbleNet45.cs

示例6: SendBluetooth

 public static void SendBluetooth(BluetoothEndPoint endpoint, BitmapSource bms)
 {
     InTheHand.Net.Sockets.BluetoothClient btc = new InTheHand.Net.Sockets.BluetoothClient();
     btc.Connect(endpoint);
     byte[] img = BmSourceToByteArr(bms);
     var nws = btc.GetStream();
     byte[] imgSize = BitConverter.GetBytes(img.Length);
     if (BitConverter.IsLittleEndian) Array.Reverse(imgSize);
     nws.Write(imgSize, 0, imgSize.Length); // write image size
     nws.Write(img, 0, img.Length); // Write image
     nws.Flush();
 }
开发者ID:EmilBechMadsen,项目名称:AEBM-ITU-PSCT-2013,代码行数:12,代码来源:BluetoothHandler.cs

示例7: Send

        /// <summary>
        /// Sends the data to the Receiver.
        /// </summary>
        /// <param name="device">The device.</param>
        /// <param name="content">The content.</param>
        /// <returns>If was sent or not.</returns>
        public async Task<bool> Send(Device device, string content)
        {
            if (device == null)
            {
                throw new ArgumentNullException("device");
            }

            if (string.IsNullOrEmpty(content))
            {
                throw new ArgumentNullException("content");
            }

            // for not block the UI it will run in a different threat
            var task = Task.Run(() =>
            {
                using (var bluetoothClient = new BluetoothClient())
                {
                    try
                    {
                        var ep = new BluetoothEndPoint(device.DeviceInfo.DeviceAddress, _serviceClassId);
                       
                        // connecting
                        bluetoothClient.Connect(ep);

                        // get stream for send the data
                        var bluetoothStream = bluetoothClient.GetStream();

                        // if all is ok to send
                        if (bluetoothClient.Connected && bluetoothStream != null)
                        {
                            // write the data in the stream
                            var buffer = System.Text.Encoding.UTF8.GetBytes(content);
                            bluetoothStream.Write(buffer, 0, buffer.Length);
                            bluetoothStream.Flush();
                            bluetoothStream.Close();
                            return true;
                        }
                        return false;
                    }
                    catch
                    {
                        // the error will be ignored and the send data will report as not sent
                        // for understood the type of the error, handle the exception
                    }
                }
                return false;
            });
            return await task;
        }
开发者ID:Kodansha,项目名称:BluetoothSample.WPF,代码行数:55,代码来源:SenderBluetoothService.cs

示例8: ServerWorker_DoWork

 void ServerWorker_DoWork(object sender, DoWorkEventArgs e)
 {
     try
     {
         client = serverSocket.AcceptBluetoothClient();
         Stream peerStream = client.GetStream();
         bWriter = new BinaryWriter(peerStream, Encoding.ASCII);
         bReader = new BinaryReader(peerStream, Encoding.ASCII);
         e.Result = true;
     }
     catch (Exception exception)
     {
         e.Result = false;
         Console.WriteLine(exception.Message);
     }
 }
开发者ID:hcilab-um,项目名称:STColorCorrection,代码行数:16,代码来源:bluetooth.cs

示例9: DoConnect

 private async void DoConnect(Action<IConnectedSphero> onSuccess, Action<Exception> onError)
 {
     try
     {
         var serviceClass = BluetoothService.SerialPort;
         var ep = new BluetoothEndPoint(PeerInformation.DeviceAddress, serviceClass);
         var client = new BluetoothClient();
         client.Connect(ep);
         var stream = client.GetStream();
         onSuccess(new ConnectedSphero(PeerInformation, stream));
     }
     catch (Exception exception)
     {
         onError(exception);
     }
 }
开发者ID:slodge,项目名称:BallControl,代码行数:16,代码来源:AvailableSphero.cs

示例10: Listen

 /*public static void md5(string source)
 {
     byte[] data = System.Text.Encoding.UTF8.GetBytes(source);
     MD5 md = MD5.Create();
     byte [] cryptoData = md.ComputeHash(data);
     Console.WriteLine(System.Text.Encoding.UTF8.GetString(cryptoData));
     md.Clear();
 }
 */
 public void Listen()
 {
     try { new BluetoothClient(); }
     catch (Exception ex)
     {
         var msg = "Bluetooth init failed: " + ex;
         MessageBox.Show(msg);
         throw new InvalidOperationException(msg, ex);
     }
     Bluetoothlistener = new BluetoothListener(OurServiceClassId);
     Bluetoothlistener.ServiceName = OurServiceName;
     Bluetoothlistener.Start();
     Bluetoothclient = Bluetoothlistener.AcceptBluetoothClient();
     byte[] data = new byte[1024];
     Ns = Bluetoothclient.GetStream();
     Ns.BeginRead(data, 0, data.Length, new AsyncCallback(ReadCallBack), data);
     DataAvailable(this, "Begin to read");
 }
开发者ID:nickraz,项目名称:probaCrypt,代码行数:27,代码来源:Program.cs

示例11: BluetoothConnect

        void BluetoothConnect()
        {
            string androidTabletMAC = "68:05:71:AA:2B:C7"; // The MAC address of my phone, lets assume we know it

            BluetoothAddress addr = BluetoothAddress.Parse(androidTabletMAC);
            //var btEndpoint = new BluetoothEndPoint(addr, 1600);
            var btClient = new BluetoothClient();
            //btClient.Connect(btEndpoint);

            Stream peerStream = btClient.GetStream();

            StreamWriter sw = new StreamWriter(peerStream);
            sw.WriteLine("Hello World");
            sw.Flush();
            sw.Close();

            btClient.Close();
            btClient.Dispose();
               // btEndpoint = null;
        }
开发者ID:AstaraelWeeper,项目名称:MainServerPlayer,代码行数:20,代码来源:Bluetooth.cs

示例12: acceptBluetoothClient

        private void acceptBluetoothClient(IAsyncResult ar)
        {
            if (client != null)
                Stop(false);

            if (listener == null)
            {
                Stop(true);
                return;
            }

            client = listener.EndAcceptBluetoothClient(ar);
            stream = client.GetStream();
            ReadAsync(stream);

            Invoke(new MethodInvoker(delegate
            {
                status.Text = string.Format("Connected to {0}.", client.RemoteMachineName);
                sendButton.Enabled = true;
            }));

            listener.BeginAcceptBluetoothClient(acceptBluetoothClient, null);
        }
开发者ID:tewarid,项目名称:NetTools,代码行数:23,代码来源:MainForm.cs

示例13: Initialize

        public override void Initialize()
        {
            var cli = new BluetoothClient();
            BluetoothDeviceInfo[] peers = cli.DiscoverDevices();
            BluetoothDeviceInfo device;
            if (string.IsNullOrEmpty(_address))
                device = peers.FirstOrDefault();
            else
            {
                device = peers.FirstOrDefault((d) => d.DeviceAddress.ToString() == _address);
            }

            if (device != null)
            {
                BluetoothAddress addr = device.DeviceAddress;
                Guid service = device.InstalledServices.FirstOrDefault();

                cli.Connect(addr, service);
                var stream = cli.GetStream();
                _bwriter = new StreamWriter(stream);
            }

            Initialized = true;
        }
开发者ID:PavelGuterman,项目名称:cakerobot,代码行数:24,代码来源:BluetoothConnector.cs

示例14: detector_DoWork

        private void detector_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                if (_bluetoothStream != null)
                    _bluetoothStream.Close();

                _client = new BluetoothClient();

                BluetoothDeviceInfo gadgeteerDevice = null;

                while (gadgeteerDevice == null)
                {
                    gadgeteerDevice = _client.DiscoverDevices().Where(d => d.DeviceName == "Gadgeteer")
                        .FirstOrDefault();
                    UpdateStatus("Still looking...");
                }

                if (gadgeteerDevice != null)
                {
                    _client.SetPin(gadgeteerDevice.DeviceAddress, "1234");
                    _client.Connect(gadgeteerDevice.DeviceAddress, BluetoothService.SerialPort);
                    _bluetoothStream = _client.GetStream();

                    e.Result = true;
                }
                else
                {
                    e.Result = false;
                }
            }
            catch (Exception)
            {
                e.Result = false;
            }
        }
开发者ID:ianlee74,项目名称:ZombieTools,代码行数:36,代码来源:ZombieDetector.cs

示例15: ListenLoop

        // 监听线程函数,用来监听来自手机端的请求并且分配各个用户的权限。
        private void ListenLoop()
        {
            while (listening)
            {
                try
                {
                    System.IO.Stream tempStream;
                    client = listener.AcceptBluetoothClient();
                    clientList.Add(client);
                    // 获取客户端信息(学生或者老师)
                    tempStream = client.GetStream();
                    byte[] mark;
                    int length;
                    mark = new byte[20];
                    length = tempStream.Read(mark, 0, mark.Length);
                    string right = System.Text.Encoding.ASCII.GetString(mark, 0, length);
                    if (right == "teacher")
                    {
                        stream = tempStream;
                        sendfileList.Add("tom.jpg");
                        WriteMessage("tom");
                        sendfileList.Add("jake.jpg");
                        WriteMessage("jake");
                        sendfileList.Add("sherry.jpg");
                        WriteMessage("sherry");
                    }
                    if (right.StartsWith("student"))
                    {
                        // 提取right中的学生名称并加进去listBox里面
                        string studentName = right.Substring(7, right.Length - 7);
                        WriteMessage(studentName);
                    }
                    SIGN_STREAMSETUP = true;

                    // 远程设备连接后,启动recieve程序
                    receiving = true;
                    new System.Threading.Thread(ReceiveLoop).Start((Object)client);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                    continue;
                }
            }
            listener.Stop();
        }
开发者ID:prafulliu,项目名称:ppter-network,代码行数:47,代码来源:MyUI.cs


注:本文中的InTheHand.Net.Sockets.BluetoothClient.GetStream方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。