Multiple Ethernet Requests

I have sketch that sends the same message out thru the ethernet bridge. It always works for the first or second (sometimes 3 times) as the logic passes thru section K but eventually it starts to fail. I've tried experimenting with long delay times but nothing seems to help. I even tried a programmatic reset of the ethernet board (not recommend, I know) but that didn't even help.

#include <stdio.h>
#include <LiquidCrystal.h>
#include <SPI.h>
#include <Ethernet.h>

// Wired Ethernet
EthernetClient client;

byte MAC_ADDR[] = { 0x90, 0xA2, 0xDA, 0x0F, 0x28, 0x43 }; // MAC of Arduino Ethernet Shield
IPAddress MY_IP(192, 168, 1, 177);

char* SERVER = "www.XXXXXXXX.com";
unsigned int PORT = 80;

// Miscellaneous
int WS_SUB;
int WS_SUBQ;
int WS_SUBT;
int WS_SUB_MAX = 5;
String WS_TEXT_MSG;
String WS_STRING;
String WS_TRACE_VALUE;
int WS_DISPLAY_CTR = 0;
String WS_DISPLAY_TRACE = "Y";
String WS_YES = "Y";

// PROCEDURE DIVISION
void setup()
{
// one time setups are in section B
}

void loop()
{
A_MAINLINE_SECTION:
A010_MAINLINE:

A020:
{
B_INITIALIZE();
}

A050_SEND_TEXT:
{
WS_TEXT_MSG = "TestTextABCDEFG";
K_SEND_TEXT();
delay(1000);
goto A050_SEND_TEXT;
}

}

void B_INITIALIZE()
{
B010_INIT_SERIAL_COMM:
{
Serial.begin(9600);
delay(1000);
}

B020_INIT_ETHERNET:
{
Ethernet.begin(MAC_ADDR, MY_IP);
delay(1000);
}

}

void K_SEND_TEXT()
{
K010_CONNECT:
{
Serial.print("Connecting to: ");
Serial.print(SERVER);
Serial.print(" ");
Serial.print("Port: ");
Serial.print(PORT);

if (client.connect(SERVER, PORT) <= 0)
{
goto K090;
}
}

K040_CONNECTION_OK:
{
Serial.println(" connected.");
}

K050_SEND:
{
Serial.print("TextMsg:");
Serial.println(WS_TEXT_MSG);

client.println("GET /arduino/YYYYYYYYYY/" +
WS_TEXT_MSG.substring(0,10) +
" HTTP/1.1");

client.println("Host: www.XXXXXXXX.com");
client.println("Connection: close");
client.println();

delay (2000);
// WAIT until server has sent bytes to this client and then
// read and print the message
while (client.available())
{
char READ_BUFFER = client.read();
Serial.print(READ_BUFFER);
WS_STRING += READ_BUFFER;
}

// Serial.println("Message returned from server:");
// Serial.println (WS_STRING);

}

K090:
{
Serial.println("Disconnecting.");
client.stop();
}

}

void T_TRACE()
{
T010:
{
if (WS_DISPLAY_CTR >= 1)
goto T020;

// first time, send CR & LF
Serial.print ("\n");
}

T020:
{
if (WS_DISPLAY_TRACE == WS_YES)
{
Serial.print(WS_TRACE_VALUE);
Serial.print("\n");
WS_DISPLAY_CTR = WS_DISPLAY_CTR + 1;
}

}
}

You are calling B_INITIALIZE every time through loop(). You should probably call that from setup().

no, it only is called once because it never loops back to where it would get called again

I think I see your problem:

             WS_STRING += READ_BUFFER;

You forgot to clear WS_STRING for each message so it just gets longer and longer. Eventually the system runs out of memory.

You also commented out the String.println(WS_STRING) so you didn't see the string length growing.

Absolutely none of those GOTOs are needed. You really ought to unlearn your Basic bad habits.

JohnWasser, Thank you.
You're a gentleman and you were correct, that fixed this problem, the new code for anyone interested is:
while (client.available())
{
char READ_BUFFER = client.read();
Serial.print(READ_BUFFER);
WS_STRING = "";
WS_STRING += READ_BUFFER;
}

PaulS, What can I say?
If they didn't want goto to be used, it wouldnt' be a part of the language.
I've heard that argument for years. GOTO-less programing. It can be overused but it can also give a programmer a wide latitude in control over how or when to break out of a routine. Your time might be better spent addressing the question asked rather than ignoring it and focussing on what you perceive as utopian code. It's an art. Different artists do things differently. Grow up.