Correct usage of etherent library?

I am trying to transmit an integer(distance reading) from one arduino to another over ethernet. I am using the wiznet library.

The first arduino is set up as a client and polls the other arduino (set up as a server) for a reading from an ultrasonic distance sensor.

My problem is writing the best code for the server as I don't fully understand the server operation. (I find it confusing that there are client instances as well as the expected server instances in the server code).

void CheckRequest()
{
    SS1.println("CheckRequest");  
    char ClientData[BUFFERLENGTH] = {'\0'};  
    EthernetClient client = server.available();   
    if (client)
    {
        RequestFailureCounter = 0;    
        unsigned short int i = 0;       
        while (client.available() && i < BUFFERLENGTH)   
        {
            ClientData[i++] = client.read();
        }
        ClientData[i] = '\0';      
        if (strcmp(ClientData, "L") == 0)    
        {
            client.print(DistanceReading);
        }
        client.flush();
        client.stop();
        RequestFailureCounter = 0;
        SS1.print("Request Received: ");
        SS1.println(ClientData);
        SS1.print("Reply sent: ");     
        SS1.println(DistanceReading);
    }
    else
    {
        SS1.println("No Request...");
    }    
}

Looking at the 1.02 ethernet examples; for the chat server they use "server.write(thisChar);" to return the response to the client whereas in the Webserver example they use "client.println();" to return the reponse. What are the pros and cons for each and which one should I use?

Also the webserver example includes the code:

    while (client.connected()) {
      if (client.available()) {
        char c = client.read();

Inserting the "while (client.connected()) " in front of the "if (client.available())".
I am just running with the " if (client.available())" as in the chat server example.
Again, what are the pros and cons of of using the client.connected() or is using just the client.available() sufficient?

client.println() is correct.

You need both client.connected() and client.available() in that embedded loop. It will stay in the "while(client.connected())" until the server closes the connection. That is the signal it is finished sending packets. Otherwise, you will get only the first packet, if it has arrived, and nothing if it hasn't arrived yet.

edit: If there is no timeout code, that could lock up in that loop if the connection fails (not closed by server, but hardware fail). Check this code in the playground for the timeout code example.
http://www.arduino.cc/playground/Code/WebClient

I find it confusing that there are client instances as well as the expected server instances in the server code

What use would a server be if nothing (that is no clients) connected to it? What, besides clients, would you call the things that connected to the server?

If you like, you can replace all the
EthernetClient client = server...
occurrences with
EthernetClient uselessBum = server...

No clients, anymore. Just uselessBums.

But, it won't change the behavior of the application.

Ahhhh... I see. I was not thinking beyond a 1 to 1 link and thought that the server instance would be linked to by the (other arduino) client and all comms to that client would be through the local server instance functions.

It seemed like having an SPI master as well as SPI slave on the same interface.

Its clearer now. Thanks.

P.S. I hope that 'uselessBums' metaphor was not a veiled reference to an un-named individual who didn't know the difference between Client and Server?!?

P.S. I hope that 'uselessBums' metaphor was not a veiled reference to an un-named individual who didn't know the difference between Client and Server?!?

Not at all. I might have chosen a different metaphor in that case... 8)