00001 00009 #include "net\tcp.h" 00010 00011 //Create a TCP socket for receiving and sending data 00012 static TCP_SOCKET tcpSocketUser = INVALID_SOCKET; 00013 00014 void tcpExample(void) 00015 { 00016 BYTE c; 00017 NODE_INFO tcpServerNode; 00018 00019 //Create a TCP socket that listens on port 54123 00020 tcpSocketUser = TCPListen(54123); 00021 00022 //An error occurred during the TCPOpen() function 00023 if (tcpSocketUser == INVALID_SOCKET) { 00024 //Add user code here to take action if required! 00025 } 00026 00027 //Infinite loop. Check if anything is received on TCP port 00028 while(1) 00029 { 00030 //Has a remote node made connection with the port we are listening on 00031 if (TCPIsConnected(tcpSocketUser)) { 00032 //Is there any data waiting for us on the TCP socket? 00033 //Because of the design of the Modtronix TCP/IP stack we have to 00034 //consume all data sent to us as soon as we detect it. 00035 if (TCPIsGetReady(tcpSocketUser)) { 00036 00037 //We are only interrested in the first byte of the message. 00038 TCPGet(tcpSocketUser, &c); 00039 00040 if (c == '0') LATB6 = 0; //Switch system LED off 00041 else if (c == '1') LATB6 = 1; //Switch system LED on 00042 00043 //Discard the socket buffer. 00044 TCPDiscard(tcpSocketUser); 00045 } 00046 } 00047 00048 //This task performs normal stack task including checking for incoming 00049 //packet, type of packet and calling appropriate stack entity to 00050 //process it. 00051 StackTask(); 00052 } 00053 }
1.5.2