Example application:
Code: Select all
#include "predef.h"
#include <stdio.h>
#include <ctype.h>
#include <startnet.h>
#include <autoupdate.h>
#include <dhcpclient.h>
#include <smarttrap.h>
#include <taskmon.h>
#include <NetworkDebug.h>
#include <tcp.h>
extern "C" {
void UserMain(void * pd);
}
const char * AppName="Test";
// Try creating a TCP connection
void TCPConnect() {
static int i = 0;
// Define our variables
IPADDR ipAddress = AsciiToIp("127.0.0.1");
int fd;
if ((fd = connect(ipAddress, 0, 1935, (2 * TICKS_PER_SECOND))) < 0) {
iprintf("Connect Failed %d\n", ++i);
} else {
iprintf("Connect succeeded %d\n", ++i);
close(fd);
}
}
void UserMain(void * pd) {
InitializeStack();
if (EthernetIP == 0) GetDHCPAddress();
OSChangePrio(MAIN_PRIO);
EnableAutoUpdate();
StartHTTP();
EnableTaskMonitor();
#ifndef _DEBUG
EnableSmartTraps();
#endif
#ifdef _DEBUG
InitializeNetworkGDB_and_Wait();
#endif
OSTimeDly(20);
while (1) {
TCPConnect();
}
iprintf("Application started\n");
while (1) {
OSTimeDly(20);
}
}
If you run a DIFF against the original vs the one I provided you'll see the changes easily (you can ignore a few changes to the critical object sections, I changed them to their expanded c instead of C++ constructor and destructor versions, while in the course of troubleshooting)