Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


Loading

Receive muliple packages

Posted by boble on December 12, 2017

Hi,

I'm using a SAM4E EK with the GMAC example from the atmel asf. I'm running into some problems with receiving multiple packages. I can receive a request and then send the website in multiple packages but can't receive multiple packages. I hope that you guys can help me because I can't think of anything else.

~~~ for( ;; ) { #if ( (LWIPVERSION) == ((1U << 24) | (3U << 16) | (2U << 8) | (LWIPVERSIONRC)) ) /* Wait for a first connection. */ pxNewConnection = netconnaccept(pxHTTPListener); #else while(netconnaccept(pxHTTPListener, &pxNewConnection) != ERROK) { vTaskDelay( webSHORTDELAY ); } #endif vParTestSetLED(webCONNLED, pdTRUE);

	if(pxNewConnection != NULL)
	{
		prvweb_ParseHTMLRequest(pxNewConnection);
		}/* end if new connection */

		vParTestSetLED(webCONN_LED, pdFALSE);

		} /* end infinite loop */
	}


	/*! \brief parse the incoming request
	*         parse the HTML request and send file
	*
	*  \param pxNetCon   Input. The netconn to use to send and receive data.
	*
	*/
	static void prvweb_ParseHTMLRequest( struct netconn *pxNetCon )
	{
		struct netbuf *pxRxBuffer;
		portCHAR *pcRxString;
		unsigned portSHORT usLength;


		#if ( (LWIP_VERSION) == ((1U << 24) | (3U << 16) | (2U << 8) | (LWIP_VERSION_RC)) )
		/* We expect to immediately get data. */
		pxRxBuffer = netconn_recv( pxNetCon );
		#else
		while(netconn_recv( pxNetCon, &pxRxBuffer) != ERR_OK)
		{
			vTaskDelay( webSHORT_DELAY );
		}
		#endif
		if( pxRxBuffer != NULL )
		{
			/* Where is the data? */
			netbuf_data( pxRxBuffer, ( void * ) &pcRxString, &usLength );

			/* Is this a GET?  We don't handle anything else. */
			if(( NULL != pcRxString)&& ( !strncmp( pcRxString, "GET", 3 ) ))
            {
            	/* Write out the HTTP OK header. */
				netconn_write( pxNetCon, webHTTP_OK, (u16_t) strlen( webHTTP_OK ), NETCONN_COPY );

				strcpy( cDynamicPage, Webpage1 );
				netconn_write( pxNetCon, cDynamicPage, (u16_t) strlen( cDynamicPage ), NETCONN_COPY );

				strcpy( cDynamicPage, Webpage2 );
				netconn_write( pxNetCon, cDynamicPage, (u16_t) strlen( cDynamicPage ), NETCONN_COPY );
            }
			if(( NULL != pcRxString) && ( !strncmp( pcRxString, "POST", 4 )))
			{
				printf("\n\r%s",pcRxString);
				netbuf_delete( pxRxBuffer);
				while(netconn_recv( pxNetCon, &pxRxBuffer) != ERR_OK)
				{
					vTaskDelay( webSHORT_DELAY );
				}
				if( pxRxBuffer != NULL )
				{
					/* Where is the data? */
					netbuf_data( pxRxBuffer, ( void * ) &pcRxString, &usLength );
					printf("\n\r%s",pcRxString);
				}



			}
			netbuf_delete( pxRxBuffer);
		}

		netconn_close( pxNetCon );
		netconn_delete( pxNetCon );

	}

~~~


Receive muliple packages

Posted by rtel on December 12, 2017

I don't think this is code we provided, or using our TCP stack. I would recommend requesting support from whoever wrote the code.


Receive muliple packages

Posted by heinbali01 on December 12, 2017

Hi Bob,

I'm using a SAM4E EK with the GMAC example from the atmel asf. I'm running into some problems with receiving multiple packages. I can receive a request and then send the website in multiple packages but can't receive multiple packages.

I'm reading your function prvweb_ParseHTMLRequest() :

~~~ netconnclose( pxNetCon ); netconndelete( pxNetCon ); ~~~

Why does this function close and delete the connection? More requests might follow...

Instead of lwIP, you may also check out FreeRTOS+TCP

If you want the latest sources, you better download the official FreeRTOS release or have a look at https://aws.amazon.com/freertos


Receive muliple packages

Posted by heinbali01 on December 13, 2017

The function that you are showing looks like sample code, a "hello world" for HTTP.

FreeRTOS+TCP contains a more complete example of a HTTP server, that keeps connections open. This server is still simple though, and it only implements the "GET" command.

It uses FreeRTOS+FAT to read files from either a RAM-disk or an SD-card.

The client browser will send a request as e.g. :

~~~ GET /index.html HTTP/1.1 Host: my_host Connection: keep-alive ~~~

The server will answer it:

~~~ HTTP/1.1 200 OK Content-Type: text/html Connection: keep-alive Content-Length: 6081

"Contents ... " ( 6081 bytes )

~~~

It is possible that the browser sends a series of GET requests, without first waiting for the returning data. Of course this technique is much more efficient than doing one request per TCP connection.


[ Back to the top ]    [ About FreeRTOS ]    [ Privacy ]    [ Sitemap ]    [ ]


Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Webinar

"OTA Update Security and Reliability" webinar presented by TI and AWS. Register here.


Careers

FreeRTOS and other embedded software careers at AWS.


Latest News

FreeRTOS kernel V10.0.1 is available for immediate download. Now MIT licensed.


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Renesas

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner