-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.iced
36 lines (28 loc) · 921 Bytes
/
index.iced
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
net = require 'net'
sig = "[ROCKSOLIDSOCKET]"
class RockSolidSocket extends net.Socket
constructor : (url) ->
super()
[@host, @port] = url.split ':'
@on 'close', =>
console.error "#{sig} Connection closed unexpectedly"
@_connect()
@on 'error', (e) =>
console.error "#{sig} Error:"
console.error e
@destroy()
@_connect()
@on 'timeout', =>
console.error "#{sig} Connection timed out"
@_connect()
@on 'connect', =>
console.log "#{sig} Connected to #{@host}:#{@port}"
@setKeepAlive(5000)
@_connect()
_connect : (attempt = 1) =>
try
@connect @port, @host
catch e
console.info "#{sig} Reconnecting to #{@host}:#{@port}"
setTimeout @_connect, 500*attempt
module.exports = RockSolidSocket