WIZnet Developer Forum

Question about W7500P web-client

Hi.
I use Mbed compiler and Wizwiki-W7500p with LAN-connection to my notebook (192.168.0.3).
I can compile ECHO-server example (set IP 192.168.0.50 for server W7500p), use program (TCP client), connect notebook with server, send data from PC, recieve answer.
It is work correctly, Im happy)).
Now I want to configure the WIZ-board as a client, and the laptop as a server: the board will initiate a connection to the laptop, send a data packet, the server-client (in PC) will display this packet, and send something in response.
Where I can found example of CLIENT for W7500p?

CODE for web-server (control LEDs via ethernet):

int main (void)
{

myledR=myledG=myledB=1;
mGND=0;
myledR=0;
step.attach(&TMR, 1);
puart.attach(&rx_interruptUART, Serial::RxIrq);

//=============================================START=============================

printstr(sss, sprintf (sss, " ZEZMANs Programm is starting...\r\n"));
wait(1);
myledG=0;


EthernetInterface eth;
eth.init(mac_addr, ip_addr, subnet_mask, gateway_addr);

eth.connect();

wait(0.1);
printstr(sss, sprintf (sss, "Server IP Address is %s\r\n", eth.getIPAddress()));
wait(0.1);
if (*(volatile uint32_t *)(W7500x_WZTOE_BASE+SIPR)==0) NVIC_SystemReset();



myledG=0;
TCPSocketServer server;
server.bind(ECHO_SERVER_PORT);
server.listen();



while (true) {
    myledR=myledG=myledB=1;
    printstr(sss, sprintf (sss, "Wait for new connection...\r\n"));
    TCPSocketConnection client;

    printstr(sss, sprintf (sss, "TCPSocketConnection client complete\r\n"));
    client.set_blocking(false, 250); // Timeout after (15)s
    TCPSS_tmr=250;
    TCPSS_blk=true;

    while(1) {
        if ((tmrT&0x1)==1) {
            myledB=0;
        } else {
            myledB=1;
        }



        if (!server.accept(client))   break;
    }

//================CONNECT==================================

    client.set_blocking(false, 15000); // Timeout after (15)s
    printstr(sss, sprintf (sss, "Connection from: %s\r\n", client.get_address()));

    myledR=myledG=myledB=1;
    tmrT=0;

    wait(0.1);
    char webt[]=  {'P','I','N','G','_','O','N',0x0d,0x0a};

    while (true) 
    {
        int n = client.receive(buffer, sizeof(buffer));
        if (n <= 0) break;
        
        // print received message to terminal
        buffer[n] = '\0';
        printf("Received message from Client :'%s'\r\n",buffer);
        
         if (buffer[0]==0x31) 
        {
            myledG=0;
            char web[]=  {'L','E','D','_','G','_','O','N',0x0d,0x0a};
            client.send_all(web,sizeof web);

        }
        if (buffer[0]==0x32) 
        {
            myledG=1;
            char web[]=  {'L','E','D','_','G','_','O','F','F',0x0d,0x0a};
            client.send_all(web,sizeof web);
        }
            
        if (buffer[0]==0x33) 
        {
            myledR=0;
            char web[]=  {'L','E','D','_','R','_','O','N',0x0d,0x0a};
            client.send_all(web,sizeof web);
        }
        if (buffer[0]==0x34) 
        {
            myledR=1;
            char web[]=  {'L','E','D','_','R','_','O','F','F',0x0d,0x0a};
            client.send_all(web,sizeof web);
        }
        if (buffer[0]==0x35) 
        {
            myledB=0;
            char web[]=  {'L','E','D','_','B','_','O','N',0x0d,0x0a};
            client.send_all(web,sizeof web);
        }
        if (buffer[0]==0x36) 
        {
            myledB=1;
            char web[]=  {'L','E','D','_','B','_','O','F','F',0x0d,0x0a};
            client.send_all(web,sizeof web);
        }

    }        

    client.close();
}

}

Please show how will look program for a client that initiates a connection to 192.168.0.3:80 and sends a packet “12345678” to the server (which the program emulates on a PC)

Copyright © 2017 WIZnet Co., Ltd. All Rights Reserved.