Ethernet library documentation

I've been playing with the Ethernet library ever since getting my wiznet and shield. I've been having a rough time understanding how the ethernet library works, and the documentation really isn't helping. I'm finding that most of the functions have a brief one line description, and use the same sample code over and over. There's also methods that aren't documented, such as client.connected(), even though it's used in one of the examples many times. I think i'm getting there, but with the rest of the documentation so good it's kind of a sore thumb.

I'm also wondering about a simple wiring diagram that shows exactly what's necessary to enable communication with the wiznet module, as if someone were breadboarding it. The closest I've seen is PNG's of Eagle schematics for the shields, which are kind of difficult to read.

I think it is because the Ethernet library is still pretty new and still getting all of the kinks worked out. The longer it's around the more the documentation will improve. Is there something specific you are having a problem with or need help on?

As far as hooking up a Wiznet module (810mj, 811mj, 812mj) it can be as simple as 4 wires. SCK to D13, MISO to D12, MOSI to D11, SCS to D10 and of course a 3.3V supply and ground to the module and a ground connection to the arduino. The pinouts for the Wiz modules are different depending on version, so check your datasheet. You can get fancier if you want all the status LEDs, but I don't really find them that useful.

I've been having trouble figuring out how, when you're running as a server, you handle two-way connections from clients. Does the Arduino code manage the connections to individual clients, storing each client in a Client object? Or is the wiznet module actually making the connections.

For instance the line "Client client = server.available()"
Does this create a new client that's specific to the IP that's connecting? Or is it agnostic, just returning a structure for anything that's trying to communicate to the server? Does it need to disconnect the client after you're done? Does that mean you have to re-connect every time you send data?

From playing around with Telnet and the chat server, it seems like the wiznet is handling all of the connections (i don't get disconnected/booted off), and the Client client = server.available() just listens for any incoming data, and uses the Client class to facilitate receiving data. Using server.print() alleviates the issue of having to make sure you're connected to a specific client to use client.print() as it prints to all listening clients (does the arduino support more than one at a time?)

The whole reason I ask is i'm writing a C++ program to communicate with the arduino over an ethernet socket, and i'm pretty new to network programming. We had a communication protocol implemented over Serial/USB, and i've been converting it to ethernet but I ran into all these problems trying to understand the library. As of today i've been able to get two-way communication and solve my re-connection problems, so I am slowly making progress. The request for documentation as much for me as for other newbies that don't quite understand what's going with the library, but i see your point with the library being new and under development.

As far as the pinouts go, that's good to know. the adafruit shield has a transistor and caps and requires a 5v source (maybe for reset?) This makes me feel a little better about connecting the module without a shield, i've already found the datasheet for the 811mj.

We'll have to wait for some of the guru's to weigh in on the specifics. I know the Wiznet supports 4 independent connections, but I'm not sure if/how the Arduino handles that. I have not yet tried multiple connections.

It sounds like you are working on a somewhat similar project to me, but I'm using C#. I'm still experimenting to decide if I want the Arduino's in client or server mode.

the adafruit shield has a transistor and caps and requires a 5v source (maybe for reset?)

I believe that is the 3.3V voltage regulator and supporting caps. Since the Arduino runs at 5V and the Wiznet 3.3V you need a second supply. This is true if you want to run the Wiznet without the shield also (don't try to run it direct off the 5V).

You may want to check out this thread:
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1234006420
there is an issue with the latest release that may be causing some of your headaches.

Hopefully Mellis or someone else can give us some insight on your other questions.

Thanks for the questions and suggestions. The Ethernet library is still relatively new and feedback like this is key to improving the documentation.

Yes, the server.available() function returns a handle to an existing client. That is, the connections persists between subsequent calls to the function.

I tried to clarify the documentation a bit and added a page for client.connected(). Does that help at all? Other thoughts?

Thanks, the additions were quite helpful. I was just confused how the client system acts in the context of accepting connections on a running server, and how connections persist/get terminated. It looks like the wiznet just accepts your connecton and won't boot you off for anything. The client.connected info is very useful since it's not immediately obvious what it does.

For what i've been working on, i'm more interested in telnet style communication than running a web-server on the arduino. Knowing how the arduino treats persistent incoming connections is more important than filling an http request and disconnecting. The chat server example is really good, but I think it could use some more comments.