Ethernet Client & Server in the same sketch

Hi

Before I set off down this route I wanted to check if I could run an Ethernet Client & Server in the same sketch or would this cause problems?

I am currently running a sketch with PID loop controlling actuators and reporting to ThingSpeak for remote logging purposes. I would now like to be able to change parameters remotely hence my thought that instigating a server in the sketch may be the way forward but something doesn't seem right so am looking for a nudge in the correct direction!!!!

That is no problem if you have an Arduino Mega 2560 + Ethernet Shield. You can run a few other services as well. There might be a delay, since the sketch can only process one at a time. I hope you are not trying to do this with an Arduino Uno + Ethernet Shield, that runs out of memory very quick. What do you have at the moment ? I2C LCD, ThingSpeak, Ethernet, Servo, PID. Maybe you want to add SD later.

On my Mega + Ethernet, I have running for the W5100 : EthernetServer (webpages + website on SD card), Adafruit_IO (not working yet), FTP client, NTP client to retrieve the date and time, ThingSpeak, E-mail (send emails), and maybe a few more. Only the EthernetServer is declared as a global variable, the others create a EthernetClient on the stack when it is needed. But it will is also work when every task uses its own global EthernetClient, and even when the tasks all use a single global EthernetClient (but not at the same time).

That is no problem

Really? Handling GET requests, and making GET requests won't interfere with the PID loop?

Before I set off down this route I wanted to check if I could run an Ethernet Client & Server in the same sketch or would this cause problems?

You have asked two questions. Yes, client/server code can be included in the same sketch. As to causing problems, that would depend on what going on in the rest of your code.

Yes I am using an Arduino Mega 2560 + Ethernet Shield ....I have already exhausted the capabilities of the UNO it appears!!

Correct I am running. What do you have at the moment ? I2C LCD, ThingSpeak, Ethernet, Servo, PID.

Is there anything I need to be careful of? Do I just need to close the client connection before opening the server connection on each loop?

Koepel.....any chance we could see your code....sounds like the bees knees. :)

You can keep the server open, as well as the client.

My code is a code from tutorials, that I put in seperate 'tabs'. They become seperate *.ino files in my project.