Node: How to keep persistent incoming connection? 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.
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 Pieter Wuille for pointing me in the right direction.