Arduino Server Hangs!(Ethernet)

I have built an C# application both server and client in c# that are used to communicate to the Arduino Server on Ethernet ,everything works fine i mean the Server written in c# tcp/ip stack works fine and connects to the arduino with the ethernet shield and when we send value from the server c# app then it goes to the Arduino also and can be read on the serial debugging monitor but the thing is after ONE INPUT the Arduino Client hangs ,why is it so?

What im trying to do is to send 12 values to control the LED Strip and it has a corresponding library to it also that is named starting from WS in the Arduino Sketch it self , im having the suspicion that it may be the SPI is getting deadlocked so i removed all the LED strip code from the arduino app then also it hangs after one value?

may be theres a problem with stream.Write(data, 0, data.Length);, but why im not able to figure it out ,when I REMOVE the led strip code i get an execption in the c# server code on line 44 OR if i keep the LED STRIP CODE in the arduino app then i can send from the c# server to the arduino ethernet only once and then for the second time the arduino app hangs? why is this so?
C# server:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;
using System.Net;

namespace Server
{
    class Program
    {
        static TcpClient connected;
        static void Main(string[] args)
        {
            TcpListener listener = new TcpListener(IPAddress.Parse("192.168.1.3"), 80);
            
            listener.Start();
            while (true)
            {
                connected = listener.AcceptTcpClient();
            sendevent:
                send();
            goto receiveevent;
        receiveevent:
            receive();
            goto sendevent;
            }
        }
        static byte[] buffer = new byte[4096];
        static void receive()
        {
            NetworkStream read = connected.GetStream();
            int data = read.Read(buffer, 0, 4096);
            Console.WriteLine("Client: "+ Encoding.ASCII.GetString(buffer, 0, data));
        }
        static void send()
        {
            byte[] data = Encoding.ASCII.GetBytes(Console.ReadLine());
            NetworkStream stream = connected.GetStream();
            stream.Write(data, 0, data.Length);
        }
    }
}

Arduino Ethernet Client sketch:

#include <SPI.h>
#include <Ethernet.h>
#include "WS2801.h"

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = {  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };//MAC address that is printed on the Sticker on your official Arduino Ethernet shield
IPAddress server(74,125,236,16); // IP off the server 

// Initialize the Ethernet client library
// with the IP address and port of the server 
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;
String inputString = "";
int led = 0;
int r = 0;
int g = 0;
int b = 0;
byte m = 0;
int dataPin = 2;
int clockPin = 3;
WS2801 strip = WS2801(240, dataPin, clockPin);

void setup() {
  // start the serial library:
  Serial.begin(9600);
  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    for(;;)
      ;
  }
  // give the Ethernet shield a second to initialize:
  delay(1000);
  Serial.println("connecting...");
  strip.begin();
  strip.show();

  // if you get a connection, report back via serial:
  if (client.connect(server, 80)) {
    Serial.println("connected");
    // Make a HTTP request:
    client.println("GET /search?q=arduino HTTP/1.0");
    client.println();
  } 
  else {
    // kf you didn't get a connection to the server:
    Serial.println("connection failed");
  }
}

void loop()
{
  // if there are incoming bytes available 
  // from the server, read them and print them:
  while (client.available()) {
    char c = client.read();
    Serial.print(c);
    inputString += c;
      if (c == '\n') 
      {
        if (inputString.length() > 12)
        {
          char cl[4];
          char cr[4];
          char cg[4];
          char cb[4];
          
         inputString.substring(0,3).toCharArray(cl,4);
         inputString.substring(3,6).toCharArray(cr,4);
         inputString.substring(6,9).toCharArray(cg,4);
         inputString.substring(9,12).toCharArray(cb,4);
//         Serial.println(inputString.substring(0,3));
//         Serial.println(inputString.substring(3,6));
//         Serial.println(inputString.substring(6,9));
//         Serial.println(inputString.substring(9,12));
//         Serial.println(cl[0]);
//         Serial.println(cl[1]);
//         Serial.println(cl[2]);
//          Serial.println(cl);
//          Serial.println(cr);
//          Serial.println(cg);
//          Serial.println(cb);
 
          led = atoi(cl);
          r =  atoi(cr);
          g =  atoi(cg);
          b =  atoi(cb);
          Serial.println(inputString);
//          Serial.println(led);
//          Serial.println(r);
//          Serial.println(g);
//          Serial.println(b);
          strip.setPixelColor(led,r,g,b);
          strip.show();
          inputString="";
        }
      }
  }

  // if the server's disconnected, stop the client:
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
    strip.setPixelColor(led,r,g,b);
    strip.show();
    // do nothing forevermore:
    for(;;)
      ;
  }
}

NOTE: Ignore the IP address that they are different here, i get them correct when i use the apps.

            while (true)
            {
                connected = listener.AcceptTcpClient();
            sendevent:
                send();
            goto receiveevent;
        receiveevent:
            receive();
            goto sendevent;
            }

Move the first line outside the while loop. Then get rid of the labels and gotos.

What im trying to do is to send 12 values

        static byte[] buffer = new byte[4096];

Average length 341 bytes? Seems a bit large when the value needs to be in the range 0 to 255.

when I REMOVE the led strip code i get an execption in the c# server code on line 44

What the Arduino does with the serial data should have no impact on the C# application. That it does indicates that the C# application is not handling the Arduino dropping off as it resets.

Some more debug prints, and sharing that output with us, would be useful.

this is the output attached:

So in C# this would be fine as per you Mr.Paul:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;
using System.Net;

namespace Server
{
    class Program
    {
        static TcpClient connected;
        static void Main(string[] args)
        {
            TcpListener listener = new TcpListener(IPAddress.Parse("192.168.1.3"), 80);
            
            listener.Start();
            connected = listener.AcceptTcpClient();
            while (true)
            {
            //sendevent:
                send();
           // goto receiveevent;
       // receiveevent:
            receive();
           // goto sendevent;
            }
        }
        static byte[] buffer = new byte[4096];
        static void receive()
        {
            NetworkStream read = connected.GetStream();
            int data = read.Read(buffer, 0, 4096);
            Console.WriteLine("Client: "+ Encoding.ASCII.GetString(buffer, 0, data));
        }
        static void send()
        {
            byte[] data = Encoding.ASCII.GetBytes(Console.ReadLine());
            NetworkStream stream = connected.GetStream();
            stream.Write(data, 0, data.Length);
        }
    }
}

UPDATE: Checked and this is what i got with this code an Exception?!(ATTACHED)

i was able to make things work but now crashes happen! may be the strip library and ethernet library both are using the SPI library!! how to go about using two systems which use the same SPI pins work together?

how to go about using two systems which use the same SPI pins work together?

Pins 11, 12, and 13 are controlled by the SPI hardware/library. Each SPI device needs a separate Slave/Chip select pin. If you mean that the two systems have different Slave select pins, you need to make sure that you are activating one, and deactivating the other, before EVERY SPI interaction.

If, by "the same SPI pins", you mean that the two systems share the same Slave select pin, then the answer is even simpler. You can't.

That is fine! i got what you mean't but is there a way to know whether the STRIP have the ability to be selected as a slave , in its driving library i didnt see one slave select till now.

BUT I think then in the case of Ethernet shield the PIN 10 is the slave select i mean , if i put this pin down the SPI communication to the Ethernet shield will go off? and then i can use it to drive the Strip?? COrrect?

BUT I think then in the case of Ethernet shield the PIN 10 is the slave select i mean , if i put this pin down the SPI communication to the Ethernet shield will go off? and then i can use it to drive the Strip?? COrrect?

As long as the strip is not also using pin 10 as the slave select, yes.