nanoframework - NanoFramework 上的套接字连接
问题描述
我遇到了一个问题,我无法使用以下代码 Telnet 到我的 Nucleo-F746ZG:
我看到 DHCP 分配了一个有效的 IP 地址,这意味着板子可以看到网络(和路由器),但是当我使用 Telnet 客户端连接时。代码永远不会离开 listener.Accept。相同的代码在 .NET Framework 下的 Windows 上运行良好。
private void ConnectionListenerThread()
{
byte [] buff = new byte[ 1024 ];
int received;
//
// Grab a collection of available network interfaces.
//
NetworkInterface[] nis = NetworkInterface.GetAllNetworkInterfaces();
//
// We need at least one interface to continue.
//
if ( nis.Length > 0 )
{
NetworkInterface ni = nis[0];
ni.EnableDhcp();
//
// Wait to be assigned an IP address.
//
while ( ni.IPv4Address == null || ni.IPv4Address.Length == 0 || ni.IPv4Address.Equals( "0.0.0.0" ) )
{
Thread.Sleep( 100 );
}
Debug.WriteLine( $"DHCP has given us the address {ni.IPv4Address},{ni.IPv4SubnetMask},{ni.IPv4GatewayAddress}" );
while ( true )
{
_clientSocket = null;
//
// We now have an IP address allocated so we can await
// incoming client connections.
//
IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Any, ListeningPort);
Socket listener = new Socket( localEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp );
try
{
listener.Bind( localEndPoint );
listener.Listen( 100 );
Debug.WriteLine( $"Waiting for an incoming connection on port {ListeningPort}.." );
_clientSocket = listener.Accept();
Debug.WriteLine( "Connected to a client" );
while ( true )
{
received = _clientSocket.Receive( buff );
if ( received > 0 )
{
OnSerialDataReceived?.Invoke( this, new EventArguments.BytesReceivedEventArgs( buff, received ) );
}
}
}
catch ( Exception ex )
{
Debug.WriteLine( $"Got a network exception: {ex.Message}" );
}
}
}
}
ListeningPort 通常设置为 54321。
这是显示已安装 NanoFramework 版本的系统信息。
System Information
HAL build info: nanoCLR running @ ST_NUCLEO144_F746ZG
Target: ST_NUCLEO144_F746ZG
Platform: STM32F7
Firmware build Info:
Date: Jul 13 2020
Type: MinSizeRel build with ChibiOS v19.1.4.1
Version: 1.4.590.0
Compiler: GNU ARM GCC v9.3.1
有人对我做错了什么有任何建议吗?
安迪
解决方案
这看起来像一个错误......请在我们的 GitHub 中提出问题。确保添加一个重现问题的项目。
推荐阅读
- ocr - tesseract 无法检测简单的二字图像中的字符
- node.js - 如何调试 Node.js 服务器?调试器跳过我的断点!(使用 VSCode)
- php - 如果消息包含使用 ajax、php 和 jquery 的超链接,则阻止表单提交
- matlab - 随机矩阵 2
- angular - github页面没有选择Angular应用程序?
- r - ROC曲线比较R中的逻辑回归和神经网络预测
- typescript - 如何在 TypeScript 的泛型函数中使用有界类型?
- class - 系统中类互连的逻辑方式
- tensorflow - 如何将 l2 归一化应用于 keras 中的图层?
- arduino - 在'{'令牌arduino led之前预期的不合格ID