Code Monkey home page Code Monkey logo

Comments (4)

ntruchsess avatar ntruchsess commented on August 24, 2024

That is happening by design of tcp. A connection is being seen as 'established' until it's terminated
(http://en.wikipedia.org/wiki/Transmission_Control_Protocol#Connection_termination). Unplugging a network-cable does not terminate an established connection by itself. Of course, without physical connectivity packets will not arrive at their destination and thus will not be acknowledged which eventually results in a timeout (resulting in a connection being terminated by each side independently). After that has happened client.connected() will return false. You have to activly send data for this to happen, just calling 'client.connected()' in a loop will never(!) time-out as there ain't no outstanding ACK-packages.

You might want to checkout https://github.com/firmata/arduino/blob/configurable/utility/EthernetClientStream.cpp which is an implementation of a 'persistent' Stream that reconnects automatically.

from arduino_uip.

ranger81 avatar ranger81 commented on August 24, 2024

Hello Norbert,
Thank you very much for your reply.

I'm pretty much of a newbie in Arduino and I don't know how to implement that EthernetClientStream into my source.

Would you be so kind to provde me a simple sample how to use EthernetClientStream together with UIPEthernet library?

This is a snippet of my currently used source:

#include <UIPEthernet.h>

EthernetClient client;

void setup() {

// Initialize all the network stuff, IP, mac, dhcp, ...

}

void loop() {

if (client.connect(IPAddress(192,168,171,1),1012))
    {
        Serial.println(F("Connected successfully"));

        while(client.connected())
        {
            // Receive data from telnet server...
            // Even if I unplug the network cable client.connected() is still true/1 .....
        }

        Serial.println(F("Got disconnected. Reconnecting..."));
                client.stop();
    }
else
    {
      Serial.println(F("Connection failed, retrying..."));
    }

Thank you very much!

from arduino_uip.

ntruchsess avatar ntruchsess commented on August 24, 2024

have a look at https://github.com/firmata/arduino/blob/configurable/examples/ConfigurableFirmata/ConfigurableFirmata.ino#L129
After having created an instance of EthernetClientStream (as in ConfigurableFirmata.ino) you can begin using all methods of Stream-class (http://arduino.cc/en/Reference/Stream).

How to detect whether the stream is actually connected? Whenever the stream is disconnected the methods read() and peek() would return -1, while write() returns 0 in this case.

from arduino_uip.

ntruchsess avatar ntruchsess commented on August 24, 2024

closing as there's no further feedback

from arduino_uip.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.