首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NanoFramework上的套接字连接

NanoFramework上的套接字连接
EN

Stack Overflow用户
提问于 2020-08-18 18:37:21
回答 1查看 140关注 0票数 0

我遇到一个问题,我无法使用以下代码远程登录到我的Nucleo-F746ZG:

我看到DHCP分配了一个有效的IP地址,这意味着当我使用Telnet客户端连接时,主板可以看到网络(和路由器)。代码永远不会离开listener.Accept。同样的代码在.NET框架下的Windows上运行良好。

代码语言:javascript
复制
        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版本的系统信息。

代码语言:javascript
复制
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

有没有人对我做错了什么有什么建议?

安迪

EN

回答 1

Stack Overflow用户

发布于 2020-08-21 17:50:09

看起来像是窃听器..。请在我们的GitHub中提出问题。确保添加一个重现该问题的项目。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63466870

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档