Echo.c example details
To verify this program, first 'ping' the DSP:
>ping 192.168.168.200
If the settings and network connections are correct, the pings will be replied.
The TCP Echo server will re-send (echo) anything it receives. To verify this, start Netcat (nc) with the following command
>nc 192.168.168.200 5031
| |
| +-- port 5031 = User Echo Port
+------------ the DSP's IP address
Any characters you type in the console window will be returned. Netcat doesn't send the characters immediately, it will send the entire string following a terminating CR. Please note that the maximum length of the character string is limited by the size of the buffer used for TCP echo (MAX_DATA = 1460).
- See also
- TCP Transmission Control Protocol
#include <stdlib.h>
#include <stdio.h>
#include <stddef.h>
#include <inttypes.h>
#include <time.h>
#include <string.h>
#define USE_STATIC_MEMORY TRUE
#define MAX_NBUFFER_SIZE (1500)
#ifdef __cplusplus
extern "C" {
#endif
#pragma CODE_SECTION(tcp_echo_cb , ".commontext")
#pragma CODE_SECTION(process_data , ".commontext")
#ifdef __cplusplus
}
#endif
#define MAX_TCP_BUFFERS 4
#ifdef USE_STATIC_MEMORY
#pragma DATA_SECTION(tcp_buffer , ".data_slow");
#endif
{
0,
0,
0,
#else
1,
#endif
};
{
data_length = net_recv_event_handler (so,
CPrintf);
if (data_length)
{
{
}
bctl-> Buf[bctl-> ri].Size = data_length;
{
bctl-> pi = bctl-> ri;
}
{
bctl-> OutOfBuffer = TRUE;
}
}
}
{
{
return;
}
if ( bctl-> OutOfBuffer )
{
{
bctl-> OutOfBuffer = FALSE;
}
}
{
buffer = (
char*)bctl-> Buf[bctl-> pi].Data;
size = (
uint32_t)bctl-> Buf[bctl-> pi].Size;
net_send_safe (so,
buffer , size, TCP_WAIT);
{
}
}
}
#pragma CODE_SECTION(main , ".commontext");
{
int main_loop = 1;
char conversion_buffer[16];
CPrintf (
" *** timer %d mapped to CPU int %d ***\r\n",
5031,
{
}
{
}
CPuts (
" network startup time [sec]: ");
"%"PRId32".%03"PRId32"\r\n"
CPuts (
"\r\n Entering main loop ...\r\n");
while ( main_loop )
{
{
CPuts (
" Any characters you type into the nc console will be echoed back\r\n when you press enter until the connection is closed.\r\n");
}
}
return (0);
}