【问题标题】:How to find Roku IP + Port on network using SSDP search in VB.NET如何在 VB.NET 中使用 SSDP 搜索在网络上查找 Roku IP + 端口
【发布时间】:2018-05-03 00:01:09
【问题描述】:

我正在尝试在我的网络上找到我的 Roku TV,显然它需要一些基于 Roku API help 的 SSDP 发现,但是,我无法使用任何 Nuget 库搜索我的设备.

我遇到了ssdpradar,并且能够通过 Visual Studio 2017 社区版本安装用于 Visual Studio (VB.NET) 的 Nuget 包。但是,我找不到任何有关如何使用它的文档。

任何建议都会有所帮助。

解决方案:

我找到了解决方案,但不是 ssdpradar 而是 RSSDP。在项目中添加块后,您可以使用以下代码行获取所有设备,然后从该列表中找到 Roku 位置(ip+port)。

Imports Rssdp

For Each founddevice As DiscoveredSsdpDevice In founddevices.Result
    If founddevice.Usn.Contains("roku:ecp") Then
        Rokulocation = founddevice.DescriptionLocation.ToString()
        Exit For
    End If
Next

【问题讨论】:

    标签: vb.net roku ssdp


    【解决方案1】:

    我最近能够成功使用名为RokuDotNet 的库。它是用 C# 编写的,但您可以将其作为项目加载到您的解决方案中并从 VB.NET 中引用它。

    我大致是这样用的:

    Imports RokuDotNet.Client
    
    Public Class Form1
        Private _discoveryClient As RokuDeviceDiscoveryClient
    
        Public Sub New()
            _discoveryClient = New RokuDeviceDiscoveryClient
            AddHandler _discoveryClient.DeviceDiscovered, AddressOf DiscoveryHandler
        End Sub
    
        Private Sub Form1_Shown(sender As Object, e As EventArgs) Handles MyBase.Shown
            _discoveryClient.DiscoverDevicesAsync()
        End Sub
    
        Private Async Sub DiscoveryHandler(sender As Object, e As DeviceDiscoveredEventArgs)
            If InvokeRequired Then
                BeginInvoke(New Action(Sub() DiscoveryHandler(sender, e)))
                Return
            End If
    
            ' Get the display name for the device (if the user entered one when setting it up)
            Dim deviceInfo = Await e.Device.Query.GetDeviceInfoAsync
            Dim name = deviceInfo.UserDeviceName
            If String.IsNullOrEmpty(name) Then
                name = deviceInfo.ModelName
            End If
            AddDevice(e.Device, name)
        End Sub
    
        Private Sub AddDevice(device As RokuDevice, name As String)
            ' Your code here
        End Sub
    End Class
    

    您可能希望在该异步函数中的 await 周围添加一个 try/catch,以便在出现网络问题时显示错误。

    【讨论】:

    • 感谢@libertyernie 的回答。我会尝试一下并更新帖子。
    • 我试过这个方法,没有成功。它说组件构建与我的框架不兼容。 @libertyernie
    猜你喜欢
    • 2016-11-24
    • 2012-10-10
    • 2013-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-17
    • 1970-01-01
    相关资源
    最近更新 更多