Instructions
261 C-Control Pro IDE
© 2013 Conrad Electronic
char text[10];
ETH_SetConnBuf(tcp_buf, 4000, 6); // 4000 byte buffer and allow 6 connections
ETH_ListenTCP(23); // Listen Telnet port
while(1)
{
ip= ETH_CheckReceiveBuf(info);
if(ip)
{
plen= info[3]; //
if(plen > 200) plen= 200; // limit to 200 bytes
ETH_ReceiveData(rbuf, plen);
txt= "Cmd:\n";
ETH_SendTCP(info[0], txt, 5); // send Cmd String
}
}
}
5.11.3 UDP Programming
UDP packets can directly be sent with ETH_SendUDP. The maximum size is 1460 bytes. This
corresponds to an MTU of 1500 and a 40-byte UDP/IP header.
In order to receive UDP packets, a receive buffer (ring buffer) is reserved with ETH_SetConnBuf
and ETH_ListenUDP will start listening to aport. Now all incoming packets arrive in the receive buf-
fer. When the buffer is full, further received data is lost. Therefore buffer should be checked regu-
larly with the Function ETH_CheckReceiveBuf. A call to ETH_ReceiveData copies the data into a
byte array buffer. If there are less bytes specified than there are bytes in the packet, the remaining
bytes of the packet are discarded from the ring buffer.
It is recommended to look at the demo programs for UDP and TCP/IP.
For default 4kb are reserved for the TCP/IP stack. Depending on the use the stack needs more
RAM or less. The memory needed is difficult to calculate, and should be determined by tests.
Examples
1. Program sends every second a string to Syslog Port 514: