我遇到一个问题,我无法使用以下代码远程登录到我的Nucleo-F746ZG:
我看到DHCP分配了一个有效的IP地址,这意味着当我使用Telnet客户端连接时,主板可以看到网络(和路由器)。代码永远不会离开listener.Accept。同样的代码在.NET框架下的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有没有人对我做错了什么有什么建议?
安迪
发布于 2020-08-21 17:50:09
看起来像是窃听器..。请在我们的GitHub中提出问题。确保添加一个重现该问题的项目。
https://stackoverflow.com/questions/63466870
复制相似问题