Send data to TCP Client without read?

Hi @all,

I have a mega with Ethernet Shield and an attached DS1820 for reading temperatures. Works well so far.

I took the example from here for starting:
http://arduino.cc/de/Reference/EthernetServer

The connect via putty works ok. I can send data and get a response.

Now I only want to send data to the connected client as soon as he gets connected.
I changed the code to send my DS1820 reading instead the client.read():

server.write(DS1820_Temp);

But this won´t work. Nothing os received at the clients side. If I press Enter in Putty (= Sending CR LF) it works and the client gets the data.

Is it possible that I write directly to a connected client without sending data from the client to the server first?

Dominik

Are you using server.available()? That will only return a client if that client has data ready to read.

The server.write() should accept any pending client connections and write the data to any client that is in the ESTABLISHED state. It should return a count of the number of clients that were sent the data.

Hi !

Yes I use server.available().

So what can I do without sending data from the client side first?

Dominik

So what can I do without sending data from the client side first?

Pretty much clients make the initial connection request to a server.

moelski: Hi @all,

I have a mega with Ethernet Shield and an attached DS1820 for reading temperatures. Works well so far.

I took the example from here for starting: http://arduino.cc/de/Reference/EthernetServer

The connect via putty works ok. I can send data and get a response.

Now I only want to send data to the connected client as soon as he gets connected. I changed the code to send my DS1820 reading instead the client.read():

server.write(DS1820_Temp);

But this won´t work. Nothing os received at the clients side. If I press Enter in Putty (= Sending CR LF) it works and the client gets the data.

Is it possible that I write directly to a connected client without sending data from the client to the server first?

Dominik

There are a number of ways to approach this

Start here

http://stackoverflow.com/questions/6147203/automating-running-command-on-linux-from-windows-using-putty

Obviously the ones where it is talking about remote command execution are not what you want - i assume you are using putty in telnet mode ?

Craig

moelski: Yes I use server.available(). So what can I do without sending data from the client side first?

Get rid of the sever.available(). Just repeat server.write() over and over (in loop()). Have the client connect, receive the write, and disconnect. (If the client doesn't disconnect it will receive the data over and over.)

@johnwasser: Have you tried that with a server send and client response yet? Normally, like http, it is a client request and a server response. I presume that is why the ethernet server library is written like it is.

But in other protocols, the server sends a "hello" to the client after the connect, but before the client sends anything, then the client responds to the server's hello (like an email server). Can the client respond to the "hello" and the Arduino server code receive it?

I have not tried that yet. Just wondering if you had.

edit: I hope I was clear. Using your theory, put this in loop().

server.println("hello");
EthernetClient client = server.available();
if(client) {
  // get response from a client responding to the hello
}

edit2: Oops! Forgot the code tags. I don't to incur the wrath of any of the moderators.