# TCPSocket Keep Alive

**URL:** <https://discourse.julialang.org/t/tcpsocket-keep-alive/12005>\
**Category:** General Usage\
**Created:** [June 27, 2018, 5:23pm UTC](https://discourse.julialang.org/t/tcpsocket-keep-alive/12005 "2018-06-27T17:23:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![randyzwitch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/randyzwitch/32/15955_2.png) [@randyzwitch](https://discourse.julialang.org/u/randyzwitch)\
**Post date:** [June 27, 2018, 5:23pm UTC](https://discourse.julialang.org/t/tcpsocket-keep-alive/12005/1 "2018-06-27T17:23:45Z")

</div>

I’ve been working with the [Thrift.jl](https://github.com/tanmaykm/Thrift.jl) package to create bindings for MapD. I am able to successfully connect to the database for many methods, but I am noticing that if I don’t submit a call for a few minutes, then I lose the connection to the database. Re-running my connection code then running the method again runs instantly.

```julia
function connect(host::String, port::Int, user::String, passwd::String, dbname::String)

    socket = TSocket(host, port)
    Thrift.set_field!(socket, :io, Base.connect(host, port))
    #transport = TBufferedTransport(socket) # https://github.com/tanmaykm/Thrift.jl/issues/12
    proto = TBinaryProtocol(socket)
    c = MapD.MapDClient(proto)

    session = MapD.connect(c, user, passwd, dbname)

    return MapDConnection(session, c)

end

```

My question is, when using `Base.connect` to create a socket, is there a way to keep the socket alive for a specified amount of time? In libuv, there is [uv\_tcp\_keepalive](http://docs.libuv.org/en/v1.x/tcp.html#c.uv_tcp_keepalive), but that doesn’t seem present for the Julia sockets.

---

<div class="post-metadata">

**Author:** ![randyzwitch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/randyzwitch/32/15955_2.png) [@randyzwitch](https://discourse.julialang.org/u/randyzwitch)\
**Post date:** [June 28, 2018, 1:43pm UTC](https://discourse.julialang.org/t/tcpsocket-keep-alive/12005/2 "2018-06-28T13:43:42Z")

</div>

Got a temporary answer from Jacob, continuing the conversation here:

[https://github.com/JuliaLang/julia/issues/27846](https://github.com/JuliaLang/julia/issues/27846)
