<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>LPC Microcontrollers中的主题 Re: VLAN with mbed</title>
    <link>https://community.nxp.com/t5/LPC-Microcontrollers/VLAN-with-mbed/m-p/1242468#M44196</link>
    <description>&lt;P&gt;Thank you xiangjun for your reply&lt;/P&gt;&lt;P&gt;Here is my code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="cpp"&gt;#include "mbed.h"
#include "gnss.h"
#include&amp;lt;string&amp;gt;
#include "EthernetInterface.h"
#include "rtos.h"
#include "TCPServer.h"
#include "TCPSocket.h"


// LEDs
DigitalOut led_1(P2_4);
DigitalOut led_2(P2_3);
DigitalOut led_3(P1_21);
DigitalOut led_4(P1_24);



// Static IP network variables
static const char*          mbedIP       = "10.5.248.45";  //IP 
static const char*          mbedMask     = "255.255.248.0";  // Mask
static const char*          mbedGateway  = "10.5.248.1";    //Gateway

static const char* recvIP = "10.5.248.121";
 
Serial pc(USBTX, USBRX);

EthernetInterface eth;

int main()
{
    pc.baud(115200);
    pc.printf("TCP server example\r\n");
    
    EthernetInterface eth;
    eth.set_network(mbedIP , mbedMask, mbedGateway );// my device address
    //eth.connect();
    
    if (0 != eth.connect())
        {
            
            pc.printf("Ethernet not connected\n\r");
            led_1=!led_1;
            return -1;
        }
    else
        {
            pc.printf("Connected Ethernet \n\r");
            led_2=!led_2; 
            
        }
            
    
    //pc.printf("The Server IP address is '%s'\r\n", eth.get_ip_address());
        
    TCPServer srv;
    TCPSocket client_sock[MAXCLIENTS];
    SocketAddress client_addr[MAXCLIENTS];
    
    int connectionStatus[MAXCLIENTS];
    
    char *buffer = new char[256];
    
    // Open the server on ethernet stack 
    srv.open(&amp;amp;eth);
    
    // Bind the HTTP port (TCP 80) to the server 
    srv.bind(10110);
    
    // Can handle x simultaneous connections 
    srv.listen(3);
   // srv.set_blocking(false);
    //client_sock[0].set_blocking(false); 
 
    int numClient = 0;
    int rcount = 0;
    int scount = 0;
    
    // initialize connection Status for client
    /*for(int i=0;i&amp;lt;MAXCLIENTS;i++)
        connectionStatus[i] = 0;*/
    
    while(1)
    {
        for(int i=0;i &amp;lt; MAXCLIENTS;i++)
        {
            //pc.printf("coonection : %i/n/r",connectionStatus[i]);
            // if not connected accept connection
            if (connectionStatus[i] == 0)
            {
                pc.printf("accept : %i\n\r",srv.accept(&amp;amp;client_sock[i], &amp;amp;client_addr[i]));
                if(srv.accept(&amp;amp;client_sock[i], &amp;amp;client_addr[i]) == 0)
                {  
                    connectionStatus[i] = 1;
                    //client_sock[i].set_blocking(false); 
                    //srv.set_blocking(false);         
                    numClient++;                    
                    pc.printf("Client Accepted %s:%d,%d\r\n", client_addr[i].get_ip_address(),client_addr[i].get_port(),numClient);
                    led_3=!led_3; 
                }
            }
            
            // if connected        
            if (connectionStatus[i] == 1)
            {                                             
                rcount = client_sock[i].recv(buffer, sizeof(buffer));
                if(rcount &amp;gt; 0)
                {
                    sprintf(buffer, "Hello Client %s:%d\r\n", client_addr[i].get_ip_address(),client_addr[i].get_port());
                    scount = client_sock[i].send(buffer, strlen(buffer));
                    led_4=!led_4;
                }
                if(rcount == 0) // client disconnected
                {
                    connectionStatus[i] = 0;
                    pc.printf("Client Disconnected %s:%d\r\n", client_addr[i].get_ip_address(),client_addr[i].get_port());
                    client_sock[i].close();
                    numClient--;                
                }                                                        
                if(scount &amp;lt; 0) // unable to send data
                {
                    connectionStatus[i] = 0;
                    pc.printf("Connection lost %s:%d\r\n", client_addr[i].get_ip_address(),client_addr[i].get_port());
                    client_sock[i].close();
                    numClient--;                
                }                                                        
            }
        }
 
        wait(0.5f);
    }
 
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't have any errors and the program compiles well but my issue is when I reached the stage when the server accept the client , there will be no acceptance and the program won't show me the IP address of the TCP client.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Looking forward to hearing from you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Nada&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 09 Mar 2021 10:57:34 GMT</pubDate>
    <dc:creator>nada1985</dc:creator>
    <dc:date>2021-03-09T10:57:34Z</dc:date>
    <item>
      <title>VLAN with mbed</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/VLAN-with-mbed/m-p/1239415#M44122</link>
      <description>&lt;P&gt;Hello every one&lt;/P&gt;&lt;P&gt;I'm new to NXP community and I'm happy to join.&lt;/P&gt;&lt;P&gt;I have mbed controller to send GPs data to araio system which is accepting the GPS data from an external TCP/IP server.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The radio is connected via a VLAN with specific number which is 10.&lt;/P&gt;&lt;P&gt;I've already enabled the VLAN on my mbed and upload the TCP&amp;nbsp; server program. Everything went well when I run the TCP client on my laptop but when I tried to connect to my radio, the server won't accept the connection.&lt;/P&gt;&lt;P&gt;I'm struggling for few weeks trying to establish the communication but yet didn't reach my goal.&lt;/P&gt;&lt;P&gt;Any help on this would be aprrecieted.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Nada&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Mar 2021 14:04:07 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/VLAN-with-mbed/m-p/1239415#M44122</guid>
      <dc:creator>nada1985</dc:creator>
      <dc:date>2021-03-03T14:04:07Z</dc:date>
    </item>
    <item>
      <title>Re: VLAN with mbed</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/VLAN-with-mbed/m-p/1239885#M44128</link>
      <description>&lt;P&gt;Hi, Nada,&lt;/P&gt;
&lt;P&gt;Can you tell us the part number you are using? do you use LWIP ethernet stack and&amp;nbsp; use the MCU as a server?&lt;/P&gt;
&lt;P&gt;Regard&lt;/P&gt;
&lt;P&gt;Xiangjun Rong&lt;/P&gt;</description>
      <pubDate>Thu, 04 Mar 2021 03:17:51 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/VLAN-with-mbed/m-p/1239885#M44128</guid>
      <dc:creator>xiangjun_rong</dc:creator>
      <dc:date>2021-03-04T03:17:51Z</dc:date>
    </item>
    <item>
      <title>Re: VLAN with mbed</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/VLAN-with-mbed/m-p/1239950#M44131</link>
      <description>&lt;P&gt;Hi Xiangjun&lt;/P&gt;&lt;P&gt;Thank you for your reply.&lt;/P&gt;&lt;P&gt;I'm using Ublox-C027 which is using the LPC1768. The mbed is my server and I'm using the opt.h from&amp;nbsp; LWIP ethernet stack to enable the VLAN support.&lt;/P&gt;&lt;P&gt;I'm using also OS 5.15&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Nada&lt;/P&gt;</description>
      <pubDate>Thu, 04 Mar 2021 06:09:05 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/VLAN-with-mbed/m-p/1239950#M44131</guid>
      <dc:creator>nada1985</dc:creator>
      <dc:date>2021-03-04T06:09:05Z</dc:date>
    </item>
    <item>
      <title>Re: VLAN with mbed</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/VLAN-with-mbed/m-p/1240271#M44142</link>
      <description>&lt;P&gt;Dear all,&lt;/P&gt;&lt;P&gt;Any help regarding my question?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Nada&lt;/P&gt;</description>
      <pubDate>Thu, 04 Mar 2021 12:32:06 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/VLAN-with-mbed/m-p/1240271#M44142</guid>
      <dc:creator>nada1985</dc:creator>
      <dc:date>2021-03-04T12:32:06Z</dc:date>
    </item>
    <item>
      <title>Re: VLAN with mbed</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/VLAN-with-mbed/m-p/1242393#M44194</link>
      <description>&lt;P&gt;Hi, Nada,&lt;/P&gt;
&lt;P&gt;can you provide the source code so that we can have a review? can you print the log of the error?&lt;/P&gt;
&lt;P&gt;BR&lt;/P&gt;
&lt;P&gt;Xiangjun Rong&lt;/P&gt;</description>
      <pubDate>Tue, 09 Mar 2021 09:20:23 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/VLAN-with-mbed/m-p/1242393#M44194</guid>
      <dc:creator>xiangjun_rong</dc:creator>
      <dc:date>2021-03-09T09:20:23Z</dc:date>
    </item>
    <item>
      <title>Re: VLAN with mbed</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/VLAN-with-mbed/m-p/1242468#M44196</link>
      <description>&lt;P&gt;Thank you xiangjun for your reply&lt;/P&gt;&lt;P&gt;Here is my code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="cpp"&gt;#include "mbed.h"
#include "gnss.h"
#include&amp;lt;string&amp;gt;
#include "EthernetInterface.h"
#include "rtos.h"
#include "TCPServer.h"
#include "TCPSocket.h"


// LEDs
DigitalOut led_1(P2_4);
DigitalOut led_2(P2_3);
DigitalOut led_3(P1_21);
DigitalOut led_4(P1_24);



// Static IP network variables
static const char*          mbedIP       = "10.5.248.45";  //IP 
static const char*          mbedMask     = "255.255.248.0";  // Mask
static const char*          mbedGateway  = "10.5.248.1";    //Gateway

static const char* recvIP = "10.5.248.121";
 
Serial pc(USBTX, USBRX);

EthernetInterface eth;

int main()
{
    pc.baud(115200);
    pc.printf("TCP server example\r\n");
    
    EthernetInterface eth;
    eth.set_network(mbedIP , mbedMask, mbedGateway );// my device address
    //eth.connect();
    
    if (0 != eth.connect())
        {
            
            pc.printf("Ethernet not connected\n\r");
            led_1=!led_1;
            return -1;
        }
    else
        {
            pc.printf("Connected Ethernet \n\r");
            led_2=!led_2; 
            
        }
            
    
    //pc.printf("The Server IP address is '%s'\r\n", eth.get_ip_address());
        
    TCPServer srv;
    TCPSocket client_sock[MAXCLIENTS];
    SocketAddress client_addr[MAXCLIENTS];
    
    int connectionStatus[MAXCLIENTS];
    
    char *buffer = new char[256];
    
    // Open the server on ethernet stack 
    srv.open(&amp;amp;eth);
    
    // Bind the HTTP port (TCP 80) to the server 
    srv.bind(10110);
    
    // Can handle x simultaneous connections 
    srv.listen(3);
   // srv.set_blocking(false);
    //client_sock[0].set_blocking(false); 
 
    int numClient = 0;
    int rcount = 0;
    int scount = 0;
    
    // initialize connection Status for client
    /*for(int i=0;i&amp;lt;MAXCLIENTS;i++)
        connectionStatus[i] = 0;*/
    
    while(1)
    {
        for(int i=0;i &amp;lt; MAXCLIENTS;i++)
        {
            //pc.printf("coonection : %i/n/r",connectionStatus[i]);
            // if not connected accept connection
            if (connectionStatus[i] == 0)
            {
                pc.printf("accept : %i\n\r",srv.accept(&amp;amp;client_sock[i], &amp;amp;client_addr[i]));
                if(srv.accept(&amp;amp;client_sock[i], &amp;amp;client_addr[i]) == 0)
                {  
                    connectionStatus[i] = 1;
                    //client_sock[i].set_blocking(false); 
                    //srv.set_blocking(false);         
                    numClient++;                    
                    pc.printf("Client Accepted %s:%d,%d\r\n", client_addr[i].get_ip_address(),client_addr[i].get_port(),numClient);
                    led_3=!led_3; 
                }
            }
            
            // if connected        
            if (connectionStatus[i] == 1)
            {                                             
                rcount = client_sock[i].recv(buffer, sizeof(buffer));
                if(rcount &amp;gt; 0)
                {
                    sprintf(buffer, "Hello Client %s:%d\r\n", client_addr[i].get_ip_address(),client_addr[i].get_port());
                    scount = client_sock[i].send(buffer, strlen(buffer));
                    led_4=!led_4;
                }
                if(rcount == 0) // client disconnected
                {
                    connectionStatus[i] = 0;
                    pc.printf("Client Disconnected %s:%d\r\n", client_addr[i].get_ip_address(),client_addr[i].get_port());
                    client_sock[i].close();
                    numClient--;                
                }                                                        
                if(scount &amp;lt; 0) // unable to send data
                {
                    connectionStatus[i] = 0;
                    pc.printf("Connection lost %s:%d\r\n", client_addr[i].get_ip_address(),client_addr[i].get_port());
                    client_sock[i].close();
                    numClient--;                
                }                                                        
            }
        }
 
        wait(0.5f);
    }
 
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't have any errors and the program compiles well but my issue is when I reached the stage when the server accept the client , there will be no acceptance and the program won't show me the IP address of the TCP client.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Looking forward to hearing from you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Nada&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Mar 2021 10:57:34 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/VLAN-with-mbed/m-p/1242468#M44196</guid>
      <dc:creator>nada1985</dc:creator>
      <dc:date>2021-03-09T10:57:34Z</dc:date>
    </item>
  </channel>
</rss>

