none
WP8的蓝牙开发可以支持蓝牙模块吗? RRS feed

  • 问题

  • private async void ConnectToDevice(PeerInformation peer) {
                if (_socket != null) {
                    // Disposing the socket with close it and release all resources associated with the socket
                    _socket.Dispose();
                }
    
                try {
                    _socket = new StreamSocket();
                    string serviceName = (String.IsNullOrWhiteSpace(peer.ServiceName)) ? txtServiceName.Text : peer.ServiceName;
    
                    // Note: If either parameter is null or empty, the call will throw an exception
                    await _socket.ConnectAsync(peer.HostName, serviceName);
    
                    // If the connection was successful, the RemoteAddress field will be populated
                    MessageBox.Show(String.Format(AppResources.Msg_ConnectedTo, _socket.Information.RemoteAddress.DisplayName));
                }
                catch (Exception ex) {
                    // In a real app, you would want to take action dependent on the type of 
                    // exception that occurred.
                    MessageBox.Show(ex.Message);
    
                    _socket.Dispose();
                    _socket = null;
                }
            }

    其中ConnectAsync要两个参数,第一个HostName可以通过PeerFinder.FindAllPeersAsync()返回的对象得到,但是第2个参数ServiceName是空的,请问我该怎么去连接蓝牙模块,也没有说明上的TCP端口什么的。。。求救。。。

    2013年11月13日 1:55

答案

全部回复