42#define MAX_PACKET_LENGTH 100
44unsigned char packetReceived[MAX_PACKET_LENGTH];
46char packetToSend[MAX_PACKET_LENGTH];
49#define NUMBER_OF_CLIENTS 6
56Connector *
const outputLEDs[6] = {
57 &ConnectorIO0, &ConnectorIO1, &ConnectorIO2, &ConnectorIO3, &ConnectorIO4, &ConnectorIO5
63 ConnectorUsb.
Mode(Connector::USB_CDC);
64 ConnectorUsb.
Speed(9600);
66 uint32_t timeout = 5000;
68 while (!ConnectorUsb &&
Milliseconds() - startTime < timeout) {
75 for(
int i=0; i<6; i++){
76 outputLEDs[i]->Mode(Connector::OUTPUT_DIGITAL);
105 IpAddress ip = IpAddress(192, 168, 0, 100);
121 EthernetTcpServer server = EthernetTcpServer(PORT_NUM);
127 EthernetTcpClient clients[NUMBER_OF_CLIENTS];
129 EthernetTcpClient tempClient;
148 tempClient = server.Accept();
151 if(tempClient.Connected()){
154 for(
int i=0; i<NUMBER_OF_CLIENTS; i++){
156 if(!clients[i].Connected()){
158 clients[i] = tempClient;
168 tempClient.Send(
"This server has reached its max number of clients. Closing connection.");
169 sprintf(packetToSend,
"This server has reached its max number of clients. Closing connection to (%s).", tempClient.RemoteIp().StringValue());
176 for(
int i=0; i<NUMBER_OF_CLIENTS; i++){
177 if (clients[i].Connected()) {
180 outputLEDs[i]->State(
true);
183 if(clients[i].BytesAvailable()){
184 sprintf(packetToSend,
"Read the following from the client(%s): ", clients[i].RemoteIp().StringValue());
187 while (clients[i].BytesAvailable()) {
189 clients[i].Read(packetReceived, MAX_PACKET_LENGTH);
193 for(
int i=0; i<MAX_PACKET_LENGTH; i++){
194 packetReceived[i]=NULL;
200 sprintf(packetToSend,
"Hello client %s",clients[i].RemoteIp().StringValue());
201 if(clients[i].Send(packetToSend) == 0){
204 sprintf(packetToSend,
"Client (%s) has been removed from client list. ", clients[i].RemoteIp().StringValue());
206 clients[i] = EthernetTcpClient();
209 outputLEDs[i]->State(
false);
216 if(clients[i].RemoteIp() != IpAddress(0,0,0,0)){
217 sprintf(packetToSend,
"Client (%s) has been removed from client list. ", clients[i].RemoteIp().StringValue());
220 clients[i] = EthernetTcpClient();
223 outputLEDs[i]->State(
false);
238 for(
int i=0; i<NUMBER_OF_CLIENTS; i++){
239 if(clients[i].RemoteIp() != IpAddress(0,0,0,0)){
240 sprintf(packetToSend,
"Client %i = %s", i, clients[i].RemoteIp().StringValue());
void Delay_ms(uint32_t ms)
Blocks operations for ms milliseconds.
Definition SysTiming.h:287
uint32_t Milliseconds(void)
Number of milliseconds since the ClearCore was initialized.
volatile const bool & PhyLinkActive()
Check the link status from the PHY.
Definition EthernetManager.h:136
IpAddress LocalIp()
Get the local IP address.
void Refresh()
Perform any necessary periodic Ethernet and LwIP updates.
bool DhcpBegin()
Set up DHCP connection to retrieve local IP.
void Setup()
Setup LwIP with the local network interface.
bool SendLine()
Send carriage return and newline characters.
Definition ISerial.h:162
virtual bool Speed(uint32_t bitsPerSecond)=0
Change the baud rate for the port.
bool Send(const char *buffer, size_t bufferSize)
Send the array of characters out the port.
Definition ISerial.h:173
char * StringValue()
Returns a string representation of the IP Address.
Definition IpAddress.h:96
virtual ConnectorModes Mode() override
Get the connector's operational mode.
Definition SerialUsb.h:210
SerialUsb ConnectorUsb
USB connector instance.
EthernetManager & EthernetMgr
Ethernet manager.