Simple TCP echo client. Connects an echo server running on a specified host and a specified port.
You need to modify ECHOSERVERIP and ECHOSERVERPORT definitions.
#define ECHOSERVERIP "192.168.1.1" #define ECHOSERVERPORT 7 #include <string-avr.h> #include <dev/nicrtl.h> #include <sys/heap.h> #include <sys/thread.h> #include <sys/timer.h> #include <sys/print.h> #include <netinet/sostream.h> #include <arpa/inet.h> static u_char buff[1024]; /* * Main application routine. * * Nut/OS automatically calls this entry after initialization. */ THREAD(NutMain, arg) { TCPSOCKET *sock; /* * Register Realtek controller at address 8300 hex * and interrupt 5 and configure lan interface. */ NutRegisterDevice(&devEth0, 0x8300, 5); NutNetAutoConfig("eth0"); for(;;) { /* * Create a socket. */ sock = NutTcpCreateSocket(); /* * Connect an echo server. */ if(NutTcpConnect(sock, inet_addr(ECHOSERVERIP), ECHOSERVERPORT) == 0) { /* * Fill buffer with letter A. */ memset(buff, 'A', 383); buff[383] = 0; /* * Send the string and receive the response. */ if(NutTcpSend(sock, buff, 384) > 0) NutTcpReceive(sock, buff, sizeof(buff)); } /* * Close our socket and take a nap. */ NutTcpCloseSocket(sock); NutSleep(1000); } }