#include "net\tcp.h" //Create a TCP socket for receiving and sending data static TCP_SOCKET tcpSocketUser = INVALID_SOCKET; void tcpExample(void) { BYTE c; NODE_INFO tcpServerNode; //Create a TCP socket that listens on port 54123 tcpSocketUser = TCPListen(54123); //An error occurred during the TCPOpen() function if (tcpSocketUser == INVALID_SOCKET) { //Add user code here to take action if required! } //Infinite loop. Check if anything is received on TCP port while(1) { //Has a remote node made connection with the port we are listening on if (TCPIsConnected(tcpSocketUser)) { //Is there any data waiting for us on the TCP socket? //Because of the design of the Modtronix TCP/IP stack we have to //consume all data sent to us as soon as we detect it. if (TCPIsGetReady(tcpSocketUser)) { //We are only interrested in the first byte of the message. TCPGet(tcpSocketUser, &c); if (c == '0') LATB6 = 0; //Switch system LED off else if (c == '1') LATB6 = 1; //Switch system LED on //Discard the socket buffer. TCPDiscard(tcpSocketUser); } } //This task performs normal stack task including checking for incoming //packet, type of packet and calling appropriate stack entity to //process it. StackTask(); } }