Ethernet and mains trigger

Hi

i am having a huge issue with my code and was hoping someone could help.
this might be a simple fix, i just can seem to see it. my arduino has a check to trigger a reset to a mini pc.
the check is done if the mains is pulled out, or if the ethernet module recieves a 1

Everytime i send a 1 to the ethernet module it resets perfectly, without any issues.
The problem happens when i do a mains check, the trigger works perfectly using the mains check, however then the ethernet part stops working.

#include <UIPEthernet.h> // Lbrary

EthernetServer server = EthernetServer(23); // 
  uint8_t mac[6] = {0x00,0x01,0x02,0x03,0x04,0x05};
  IPAddress myIP(192,168,1,60);
  IPAddress gateway(192, 168, 1, 254);
IPAddress subnet(255, 255, 255, 0);


String readString;
int x;
int led = 9;
///////////////////////////////////////////////////////////////////////


int val = 0; 

int checking = 1;
int doublecheck;

int signal_in = 9;

int connect_led = 8;     //red
int dissconnect_led = 7; //green
int voltage_inPin = 6;
int relay = 5;

int chiko;

//////////////////////////////////////////////////////////////////////

void setup()
{
  Serial.begin(9600);
Ethernet.begin(mac,myIP,gateway,subnet);
 
  ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  pinMode(signal_in, OUTPUT);  
  pinMode(connect_led, OUTPUT); 
  pinMode(dissconnect_led, OUTPUT);
  pinMode(relay, OUTPUT);
  pinMode(voltage_inPin, INPUT);
  //digitalWrite(relay, HIGH);
  ///////////////////////////////////////////////////////////////////////////////////////////////////////////
}

void loop()
{
   server.begin();
   EthernetClient client = server.available();

  ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  val = digitalRead(voltage_inPin);
 ///////////////////////////////////////////////////////////////////////////////////////////////////////////
while (client.available()> 0) {
char c = client.read();
   readString += c; //makes the string readString
    delay(5);  //slow looping to allow buffer to fill with next character 
}

if (readString.length() >0) {
int commaIndex = readString.indexOf(',');
   int secondCommaIndex = readString.indexOf(',', commaIndex+1);
   
String firstValue = readString.substring(0, commaIndex);
String secondValue = readString.substring(commaIndex+1, secondCommaIndex);
String thirdValue = readString.substring(secondCommaIndex+1); // To the end of the string

x = firstValue.toInt();
int y = secondValue.toInt();
int z = thirdValue.toInt();  
}

if (x == 1){

  digitalWrite(signal_in, HIGH);
  chiko = 1;
}else{

  digitalWrite(signal_in, LOW);
  chiko = 0;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////

if (val == 0) 
   {
    digitalWrite(dissconnect_led, HIGH);
     digitalWrite(connect_led, LOW);
     doublecheck = 1;
    //Serial.println("0");
  }
  
  if (val == 1 || chiko == 1){

     Serial.println("1");
     digitalWrite(dissconnect_led, LOW);
digitalWrite(connect_led, HIGH);
//digitalWrite(signal_in, HIGH);
checking = 0; 
  }

if(checking == 0){
delay(11000);
digitalWrite(relay, LOW);
doublecheck = 0;
checking = 1;
}


if(checking == 1 && doublecheck == 0){
 digitalWrite(relay, LOW);  
}

else{
 digitalWrite(relay, HIGH);
}


  ///////////////////////////////////////////////////////////////////////////////////////////////////////////
 readString=""; //empty for next input
  x = 0;
  //client.stop();
  delay(300);
}

my theroy is that once the mains check works the loop does not begin again. i have uploaded the code, hoping someone out there can help me.

oh yeah also once the mains part works and the ethernet part stops working. the only way to fix it is to shut down power to the arduino.

thank you

    delay(5);  //slow looping to allow buffer to fill with next character

This

is

a

piss-

poor

way

to

read

all

the

data.

Spin in a while loop, while the client is connected.
In that while loop, use the while loop to read all the data AS SOON AS IT ARRIVES.

The inner while loop loop will start and stop many times. The outer while loop will end as soon as the server has sent the complete response.

Speaking of piss-poor, your code looks like it was typed by a drunken monkey. Use Tools + Auto Format to sober that monkey up.

the check is done if the mains is pulled out, or if the ethernet module recieves a 1

What is the mains powering?

ledconnect and leddisconnect names might mean something to you. They mean less than nothing to me.

checking, val, x, etc. might mean something to you. They mean less than nothing to me.