t0xa / gelfj

Graylog Extended Log Format (GELF) implementation in Java and log4j appender without any dependencies.
https://github.com/t0xa/gelfj/wiki
Other
186 stars 116 forks source link

Closing connection through timeout #84

Open dmytrokarimov opened 10 years ago

dmytrokarimov commented 10 years ago

Hi. Can you add support of closing connection after a period of inactivity

Here is the simple example what I want (class GelfTCPSender):

try {
    // reconnect if necessary or 5 min timeout occurred
    if (socket == null || os == null || lastSendTime + 5 * 60 * 1000 < System.currentTimeMillis()) {
        if (socket != null){
            socket.close();
        }
        socket = new Socket(host, port);
        os = socket.getOutputStream();
    }
    os.write(message.toTCPBuffer().array());
    lastSendTime = System.currentTimeMillis();

    return true;
} catch (IOException e) {
    // if an error occours, signal failure
    socket = null;
    return false;
}

I have some problems with firewall and keep-alive sessions.

skorhone commented 8 years ago

Would tcp keepalive resolve this issue?