Return to SDK Examples for Microchip Studio
#include "ClearCore.h"
IpAddress serverIp = IpAddress(192, 168, 0, 123);
#define PORT_NUM 8888
#define MAX_PACKET_LENGTH 100
unsigned char packetReceived[MAX_PACKET_LENGTH];
bool usingDhcp = true;
int main(void) {
uint32_t timeout = 5000;
while (!ConnectorUsb &&
Milliseconds() - startTime < timeout) {
continue;
}
}
if (usingDhcp) {
if (dhcpSuccess) {
} else {
while (true) {
continue;
}
}
} else {
IpAddress ip = IpAddress(192, 168, 0, 103);
}
EthernetTcpClient client;
if (!client.Connect(serverIp, PORT_NUM)) {
}
while(true){
}
if(!client.Connected()){
uint32_t delay = 1000;
if (!client.Connect(serverIp, PORT_NUM)) {
}
}
} else {
if( client.Send("Hello server") >0)
{
bool receivedMessage = false;
uint32_t delay = 1000;
if (client.Read(packetReceived, MAX_PACKET_LENGTH) > 0)
{
receivedMessage = true;
for(int i=0; i<MAX_PACKET_LENGTH; i++){
packetReceived[i]=NULL;
}
}
}
if (!receivedMessage){
}else{
}
}
else
{
client.Close();
}
}
}
}