ethernet connect request message issue

I am using ethernet shield with due. I am using interrupts to process ethernet messages. When I use telnet on my pc to connect to the shield, the interrupt is correctly received, but when I check, server.available and client.connected are both set to false and the program wrongly assumes that there is still no one connected. The connection is actually established and is working fine though. Next I type a command in the telnet session, this is received fine and both server.available and client.connected behave properly. Why these dont work ok when the initial connection is established. Most of the functionality is working fine, but now I need to implement new feature where I need to keep track of if I am connected or not and the very first message fails.

The server.available() function depends on receiving something from the client. Just establishing a connection is not enough.

This code will get the status of all the sockets. It will show connections without the client sending any characters.

#include <utility/w5100.h>

byte socketStat[MAX_SOCK_NUM];

void ShowSockStatus()
{
  for (int i = 0; i < MAX_SOCK_NUM; i++) {
    Serial.print(F("Socket#"));
    Serial.print(i);
    uint8_t s = W5100.readSnSR(i);
    socketStat[i] = s;
    Serial.print(F(":0x"));
    Serial.print(s,16);
    Serial.print(F(" "));
    Serial.print(W5100.readSnPORT(i));
    Serial.print(F(" D:"));
    uint8_t dip[4];
    W5100.readSnDIPR(i, dip);
    for (int j=0; j<4; j++) {
      Serial.print(dip[j],10);
      if (j<3) Serial.print(".");
    }
    Serial.print(F("("));
    Serial.print(W5100.readSnDPORT(i));
    Serial.println(F(")"));
  }
}

A socket status list:
0x0 = available.
0x14 = socket waiting for a connection
0x17 = socket connected to a client if a server, or a server if a client.
0x22 = UDP socket.

thanks, I will give this code a try.

I also faced another issue with this. I need to send out a udp message periodically. I have setup a timer interrupt for this, which seems to be working fine. I can put a println in the interrupt handler and it works fine. But when I put code in there for sending out a udp message, it works fine too, but after that the execution comes out of the main loop it was executing before it entered the interrupt handler. Any ideas as to why its happening with the udp calls only and not with println.

I don’t put any SPI device calls in in interrupt handler. Many require interrupts to be enabled for timing.

I don’t call any Serial functions in the interrupt handler either.

the println i had just put for debugging. Is there a way to get this to work with some inerrupt enabling disabling or setting interrupt priorities etc. i dont want to set a variable in the interrupt handler and check it in the loop as the main loop is a few microseconds and this periodic interrupt is once every few seconds. I will be unnecessarily checking the flag way too often in my loop.