Report
11 months, 2 weeks ago.

TCPServer - TCPSocket send to web browser notvalid

I send HTML Language to client (web browser) via TCPSocket and TCPServer. At web browser of client show not valid. I view source code at web browser, not found some code. I think the web browser not show when source code over 1024 of length. Please help me to web browser show successful.

I use MBED-OS 5.x and STM32 F746zg

This is my code

#include "mbed.h"
#include "EthernetInterface.h"

EthernetInterface net;
TCPServer srv;
TCPSocket client_sock;
SocketAddress client_addr;
char *wbuffer = new char[200000];
int i;

int main() {
    printf("\r\n\r\nStarting up...\r\n");
    printf("###############\r\n");
    printf("Getting Ethernet Socket...\r\n");
    
    net.connect();
    
    const char *ip = net.get_ip_address();
    printf("IP address: %s\r\n", ip ? ip : "No IP\r\n");
    printf("NetMask: %s\r\n", net.get_netmask());
    printf("Gateway Address: %s\r\n", net.get_gateway());
    printf("Mac Address: %s\r\n", net.get_mac_address());    
    
    srv.open(&net);
    srv.bind(net.get_ip_address(), 80);
    srv.listen(1);    

    while(1) {      
        srv.accept(&client_sock, &client_addr);
        
        strcpy(wbuffer, "<!DOCTYPE html>\n<HTML>\n<HEAD>\n");
        strcat(wbuffer, "<meta http-equiv=\"Content-Type\" content=\"text/html;charset=UTF-8\">\n");
        strcat(wbuffer, "<TITLE>Time Record List</TITLE>\n</HEAD>\n<BODY>\n<center>\n");
        strcat(wbuffer, "<TABLE width=\"50%\" bgcolor=\"#4ff3ff\" border=\"1\"  cellpadding=\"0\" cellspacing=\"0\" >\n");
        strcat(wbuffer, "<TH width=\"70%\">Time List</TH>\n");
        
        i=0;
        for (i = 0; i <= 2000 ; i++) {
            strcat(wbuffer, "<TR align=\"center\">\n<TD>");
            strcat(wbuffer, "A";
            strcat(wbuffer, "</TD>\n");
            strcat(wbuffer, "</TR>\n");
        }                  
        strcat(wbuffer, "</TABLE>\n");
        strcat(wbuffer, "</center>\n</BODY>\n</HTML>");        
    
        client_sock.send(wbuffer, strlen(wbuffer));
        
        client_sock.close();
    }//end while    
}

I view wbuffer with printf , It's normal. but at web browser it error.

Source code at web browser of client

<!DOCTYPE html>
<HTML>
	<HEAD>
		<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
		<TITLE>Time Record List</TITLE>
	</HEAD>
<BODY>
	<center>
		<TABLE width="50%" bgcolor="#4ff3ff" border="1"  cellpadding="0" cellspacing="0" >
			<TH width="70%">Time List</TH>
		   	<TR align="center">
				<TD>A</TD>
			</TR>
			<TR align="center">
				<TD>A</TD>
			</TR>
			<TR align="center">
				<TD>A</TD>
			</TR>
			<TR align="center">
				<TD>A</TD>
			</TR>
			<TR align="center">
				<TD>A</TD>
			</TR>
			<TR align="center">
				<TD>A</TD>
			</TR>
			<TR align="center">
				<TD>A</TD>
			</TR><TR align="center">
				<TD>A</TD>
			</TR>
			<TR align="center">
				<TD>A</TD>
			</TR>
			<TR align="center">
				<TD>A</TD>
			</TR>
			<TR align="center">
				<TD>A</TD>
			</TR>
			<TR align="center">
				<TD>A</TD>
			</TR>
			<TR align="center">
				<TD>A</TD>
			</TR>
			<TR align="center">
				<TD>A</TD>
			</TR>
			<TR align="center">
				<TD>A</T

Sorry for my english language. Thankyou so much.

SOLVED!

I updated MBED-OS to last revise and try to run again. It work.

posted by Teerawat Khamsat 14 May 2018
Comment on this question
Be the first to answer this question.

To post an answer, please log in.