<p><strong>Solution:</strong> The node has been sending my script <code>ping</code> messages, but my script was not responding with <code>pong</code> messages.</p>

<blockquote>
  <p>The ping message is sent primarily to confirm that the TCP/IP connection is still valid. An error in transmission is presumed to be a closed connection and the address is removed as a current peer. <a href="https://en.bitcoin.it/wiki/Protocol_documentation#ping" rel="nofollow noreferrer">https://en.bitcoin.it/wiki/Protocol_documentation#ping</a></p>
</blockquote>

<p>Therefore, my script "node" appeared to be unresponsive, so the local node would drop the connection.</p>

<hr>

<p>Thanks to <a href="https://bitcoin.stackexchange.com/users/208/pieter-wuille" title="Pieter Wuille">Pieter Wuille</a> for pointing me in the right direction.</p>

CC BY-SA 3.0
2016-11-21T20:54:14.227Z
2016-11-21T20:54:14.227Z
2017-04-13T12:47:33.610Z
inersha
<p>I've written a simple script "node" that will connect to the local node running on my computer.</p>

<p>I can see that it's connected using:</p>

<pre><code>$ bitcoin-cli getpeerinfo

{
    "id": 27,
    "addr": "127.0.0.1:37992",
    "addrlocal": "127.0.0.1:18333",
    "services": "0000000000000001",
    "relaytxes": true,
    "lastsend": 1479746037,
    "lastrecv": 1479746037,
    "bytessent": 325460,
    "bytesrecv": 6007,
    "conntime": 1479745618,
    "timeoffset": 0,
    "pingwait": 419.673504,
    "version": 60002,
    "subver": "",
    "inbound": true,
    "startingheight": 0,
    "banscore": 0,
    "synced_headers": -1,
    "synced_blocks": -1,
    "inflight": [
    ],
    "whitelisted": false,
    "bytessent_per_msg": {
      "block": 236393,
      "getheaders": 1053,
      "inv": 5898,
      "ping": 32,
      "tx": 81934,
      "verack": 24,
      "version": 126
    },
    "bytesrecv_per_msg": {
      "getdata": 5898,
      "version": 109
    }
  }
}
</code></pre>

<p>However, the script will eventually lose connection to my local node and stop receiving messages. This usually happens within a space of an hour.</p>

<ul>
<li>What causes a node to drop a connection to an incoming node?</li>
<li>Is it possible to make my local node to allow a permanent incoming connection (from my local script)?</li>
</ul>

<hr>

<p>EDIT: I've tried <code>addnode=127.0.0.1</code> in my <em>bitcoin.conf</em>, but it doesn't help with reconnecting if the connection is dropped.</p>

CC BY-SA 3.0
2016-11-21T18:50:29.610Z
`addnode` just tells your node to consider connecting to that address. It doesn't treat inbound connections specially, or connect to the address.
Nick ODell
CC BY-SA 3.0
2016-11-21T18:57:54.323Z
Are you responding to ping requests? it may be dropping the connection because you look unresponsive.
Pieter Wuille
CC BY-SA 3.0
2016-11-21T20:29:40.403Z
@PieterWuille. No, I've not been responding to ping requests. Thank you.
inersha
<network><nodes><local>
Node: How to keep persistent incoming connection?
inersha
# Node: How to keep persistent incoming connection?

(Asked by: username_0 on 2016-11-21)

I've written a simple script "node" that will connect to the local node running on my computer.

I can see that it's connected using:

```
$ bitcoin-cli getpeerinfo

{
    "id": 27,
    "addr": "127.0.0.1:37992",
    "addrlocal": "127.0.0.1:18333",
    "services": "0000000000000001",
    "relaytxes": true,
    "lastsend": 1479746037,
    "lastrecv": 1479746037,
    "bytessent": 325460,
    "bytesrecv": 6007,
    "conntime": 1479745618,
    "timeoffset": 0,
    "pingwait": 419.673504,
    "version": 60002,
    "subver": "",
    "inbound": true,
    "startingheight": 0,
    "banscore": 0,
    "synced_headers": -1,
    "synced_blocks": -1,
    "inflight": [
    ],
    "whitelisted": false,
    "bytessent_per_msg": {
      "block": 236393,
      "getheaders": 1053,
      "inv": 5898,
      "ping": 32,
      "tx": 81934,
      "verack": 24,
      "version": 126
    },
    "bytesrecv_per_msg": {
      "getdata": 5898,
      "version": 109
    }
  }
}

```

However, the script will eventually lose connection to my local node and stop receiving messages. This usually happens within a space of an hour.

* What causes a node to drop a connection to an incoming node?
* Is it possible to make my local node to allow a permanent incoming connection (from my local script)?

---

EDIT: I've tried `addnode=127.0.0.1` in my *bitcoin.conf*, but it doesn't help with reconnecting if the connection is dropped.

**Tags:** network, nodes, local

> **Comments:**
> **username_1**: `addnode` just tells your node to consider connecting to that address. It doesn't treat inbound connections specially, or connect to the address.  
> **username_2**: Are you responding to ping requests? it may be dropping the connection because you look unresponsive.  
> **username_0**: @username_2. No, I've not been responding to ping requests. Thank you.  

---

## 1 answers

### Answer by username_0 on 2016-11-21. Score: 1 | Accepted answer

**Solution:** The node has been sending my script `ping` messages, but my script was not responding with `pong` messages.

> The ping message is sent primarily to confirm that the TCP/IP connection is still valid. An error in transmission is presumed to be a closed connection and the address is removed as a current peer. <https://en.bitcoin.it/wiki/Protocol_documentation#ping>

Therefore, my script "node" appeared to be unresponsive, so the local node would drop the connection.

---

Thanks to [username_2 username_2](https://bitcoin.stackexchange.com/users/208/username_2-username_2 "username_2 username_2") for pointing me in the right direction.


---

