【问题标题】:Using the windows azure Connectthedots.io example and running into some trouble with the C# gateway.exe socket connection使用 windows azure Connectthedots.io 示例并在 C# gateway.exe 套接字连接上遇到一些问题
【发布时间】:2015-08-17 22:26:38
【问题描述】:

我正在尝试使用 Connectthedots.io 示例,并在我的 Windows 8.1 机器上运行 gateway.exe 程序。我使用声音计示例 (https://github.com/MSOpenTech/connectthedots/blob/master/Devices/GatewayConnectedDevices/BtUSB_2_BtUART_Example/BtUSB_2_BtUART_Example.py) 中的代码设置了一个虚拟设备,尽管用生成的随机值 (random.randint) 替换了来自 USB 的读取。

我运行 gateway.exe,然后运行虚拟传感器 python 脚本。虚拟传感器脚本表示它已连接到套接字并将 JSON 数据发送到套接字。网关无法识别它,并在日志文件中给出此错误。

2015-06-03 10:55:16.8137 ERROR Error on lock: {"ClassName":"System.AggregateException","Message":"One or more errors occurred.","Data":null,"InnerException":{"NativeErrorCode":11001,"ClassName":"System.Net.Sockets.SocketException","Message":"No such host is known","Data":null,"InnerException":null,"HelpURL":null,"StackTraceString":"   at System.Net.Dns.GetAddrInfo(String name)\r\n   at System.Net.Dns.InternalGetHostByName(String hostName, Boolean includeIPv6)\r\n   at System.Net.Dns.GetHostEntry(String hostNameOrAddress)\r\n   at Amqp.TcpTransport.<ConnectAsync>d__5.MoveNext()","RemoteStackTraceString":null,"RemoteStackIndex":0,"ExceptionMethod":"8\nGetAddrInfo\nSystem, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\nSystem.Net.Dns\nSystem.Net.IPHostEntry GetAddrInfo(System.String)","HResult":-2147467259,"Source":"System","WatsonBuckets":null},"HelpURL":null,"StackTraceString":"   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)\r\n   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)\r\n   at System.Threading.Tasks.Task.Wait()\r\n   at Amqp.TcpTransport.Connect(Connection connection, Address address, Boolean noVerification)\r\n   at Amqp.Connection.Connect(SaslProfile saslProfile, Open open)\r\n   at Amqp.Connection..ctor(Address address, SaslProfile saslProfile, Open open, OnOpened onOpened)\r\n   at Amqp.Connection..ctor(Address address)\r\n   at Microsoft.ConnectTheDots.Gateway.AMQPSender`1.ReliableSender.EstablishSender() in c:\\Users\\Cameron\\Desktop\\connectthedots-master\\Devices\\Gateways\\GatewayService\\Gateway\\Utils\\MessageSender\\AMQPSender.cs:line 129","RemoteStackTraceString":null,"RemoteStackIndex":0,"ExceptionMethod":"8\nThrowIfExceptional\nmscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\nSystem.Threading.Tasks.Task\nVoid ThrowIfExceptional(Boolean)","HResult":-2146233088,"Source":"mscorlib","WatsonBuckets":null,"InnerExceptions":[{"NativeErrorCode":11001,"ClassName":"System.Net.Sockets.SocketException","Message":"No such host is known","Data":null,"InnerException":null,"HelpURL":null,"StackTraceString":"   at System.Net.Dns.GetAddrInfo(String name)\r\n   at System.Net.Dns.InternalGetHostByName(String hostName, Boolean includeIPv6)\r\n   at System.Net.Dns.GetHostEntry(String hostNameOrAddress)\r\n   at Amqp.TcpTransport.<ConnectAsync>d__5.MoveNext()","RemoteStackTraceString":null,"RemoteStackIndex":0,"ExceptionMethod":"8\nGetAddrInfo\nSystem, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\nSystem.Net.Dns\nSystem.Net.IPHostEntry GetAddrInfo(System.String)","HResult":-2147467259,"Source":"System","WatsonBuckets":null}]}
2015-06-03 10:55:16.8414 ERROR Exception on sendObject reference not set to an instance of an object.
2015-06-03 10:55:16.8999 ERROR Error on lock: {"ClassName":"System.AggregateException","Message":"One or more errors occurred.","Data":null,"InnerException":{"NativeErrorCode":11001,"ClassName":"System.Net.Sockets.SocketException","Message":"No such host is known","Data":null,"InnerException":null,"HelpURL":null,"StackTraceString":"   at System.Net.Dns.GetAddrInfo(String name)\r\n   at System.Net.Dns.InternalGetHostByName(String hostName, Boolean includeIPv6)\r\n   at System.Net.Dns.GetHostEntry(String hostNameOrAddress)\r\n   at Amqp.TcpTransport.<ConnectAsync>d__5.MoveNext()","RemoteStackTraceString":null,"RemoteStackIndex":0,"ExceptionMethod":"8\nGetAddrInfo\nSystem, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\nSystem.Net.Dns\nSystem.Net.IPHostEntry GetAddrInfo(System.String)","HResult":-2147467259,"Source":"System","WatsonBuckets":null},"HelpURL":null,"StackTraceString":"   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)\r\n   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)\r\n   at System.Threading.Tasks.Task.Wait()\r\n   at Amqp.TcpTransport.Connect(Connection connection, Address address, Boolean noVerification)\r\n   at Amqp.Connection.Connect(SaslProfile saslProfile, Open open)\r\n   at Amqp.Connection..ctor(Address address, SaslProfile saslProfile, Open open, OnOpened onOpened)\r\n   at Amqp.Connection..ctor(Address address)\r\n   at Microsoft.ConnectTheDots.Gateway.AMQPSender`1.ReliableSender.EstablishSender() in c:\\Users\\Cameron\\Desktop\\connectthedots-master\\Devices\\Gateways\\GatewayService\\Gateway\\Utils\\MessageSender\\AMQPSender.cs:line 129","RemoteStackTraceString":null,"RemoteStackIndex":0,"ExceptionMethod":"8\nThrowIfExceptional\nmscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\nSystem.Threading.Tasks.Task\nVoid ThrowIfExceptional(Boolean)","HResult":-2146233088,"Source":"mscorlib","WatsonBuckets":null,"InnerExceptions":[{"NativeErrorCode":11001,"ClassName":"System.Net.Sockets.SocketException","Message":"No such host is known","Data":null,"InnerException":null,"HelpURL":null,"StackTraceString":"   at System.Net.Dns.GetAddrInfo(String name)\r\n   at System.Net.Dns.InternalGetHostByName(String hostName, Boolean includeIPv6)\r\n   at System.Net.Dns.GetHostEntry(String hostNameOrAddress)\r\n   at Amqp.TcpTransport.<ConnectAsync>d__5.MoveNext()","RemoteStackTraceString":null,"RemoteStackIndex":0,"ExceptionMethod":"8\nGetAddrInfo\nSystem, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\nSystem.Net.Dns\nSystem.Net.IPHostEntry GetAddrInfo(System.String)","HResult":-2147467259,"Source":"System","WatsonBuckets":null}]}
2015-06-03 10:55:16.9280 ERROR Exception on sendObject reference not set to an instance of an object.
2015-06-03 10:55:16.9553 ERROR Exception in task:    at Microsoft.ConnectTheDots.Gateway.AMQPSender`1.SendAmqpMessage(Message m) in c:\Users\Cameron\Desktop\connectthedots-master\Devices\Gateways\GatewayService\Gateway\Utils\MessageSender\AMQPSender.cs:line 355
   at Microsoft.ConnectTheDots.Gateway.AMQPSender`1.<PrepareAndSend>b__0(Message m) in c:\Users\Cameron\Desktop\connectthedots-master\Devices\Gateways\GatewayService\Gateway\Utils\MessageSender\AMQPSender.cs:line 324
   at Microsoft.ConnectTheDots.Common.SafeAction`1.SafeInvoke(TParam obj) in c:\Users\Cameron\Desktop\connectthedots-master\Devices\Gateways\GatewayService\Common\SafeAction.cs:line 48
2015-06-03 10:55:16.9553 ERROR Message in task: Object reference not set to an instance of an object.

为什么这不起作用?是不是因为windows不兼容?因为我没有修改 C# 网关代码,而且我的虚拟传感器似乎正在连接和发送数据,所以给出了什么?我想微软给出的例子可以在 Windows 8.1 上运行。

【问题讨论】:

    标签: c# python windows sockets azure


    【解决方案1】:

    请问您是否从日志文件 (connectthedots-master\Devices\Gateways\GatewayService\WindowsEXE\bin\Debug\logs) 中收到错误消息?根据我的理解,看起来问题是因为您没有正确设置 app.config (GatewayExe) 中的 AMQPServiceConfig 的值。

    根据我的经验,您有两种选择可以从 Azure 事件中心获取值:

    选项1

    利用代码示例中的 AzurePrep 项目生成包含如下信息的日志文件:

    然后使用以下格式替换 Microsoft.ConnectTheDots.GatewayExe 项目中 app.config 中的信息。

    AMQPSAddress="amqps://[key-name]:[key]@[namespace].servicebus.windows.net"

    选项2

    1. 浏览http://manage.windowsazure.com
    2. 在左侧导航菜单中选择服务总线
    3. 选择你的命名空间
    4. 从顶部菜单中选择事件中心 -> 选择 ehdevices -> 选择底部的连接信息选项卡

    然后使用下面的格式替换app.config中的信息

    AMQPSAddress="amqps://[key-name]:[key]@[namespace].servicebus.windows.net"

    由于我无法完全重现您的问题,请提供一些其他提示供您参考,以防我可能错过任何了解您的问题的信息

    • 请在设置 VS 时使用“以管理员身份运行” 网关服务,否则服务不会监听端口 它接收来自 BtUSB_2_BtUART_Example Python 的请求 脚本。
    • 使用 Python2 而不是 Python3,因为某些语法存在差异 在 Python3 中,否则可能需要修改 BtUSB_2_BtUART_Example.py 文件中的代码

    Blow 是我这边的代码示例运行结果,我可以在我的 Azure 门户 - ehdevices 仪表板上看到数字。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-27
      • 1970-01-01
      • 1970-01-01
      • 2015-04-25
      • 2011-07-10
      • 2018-05-11
      相关资源
      最近更新 更多