Changeset - 6044e527d795
[Not reviewed]
default
0 2 0
Drew Perttula - 9 years ago 2016-06-05 03:39:39
drewp@bigasterisk.com
ping loop (and some lines from the next patch). My setup seemed to be dropping WS after like 30 sec.
Ignore-this: 7d2150afcf21628882d78914898c04d4
2 files changed with 14 insertions and 0 deletions:
0 comments (0 inline, 0 general)
bin/rdfdb
Show inline comments
 
@@ -414,12 +414,15 @@ class WebsocketClient(cyclone.websocket.
 
    def connectionLost(self, reason):
 
        log.info("bye ws client %r", self.wsClient)
 
        self.settings.db.clientErrored(
 
            Failure(WebsocketDisconnect(reason)), self.wsClient)
 

	
 
    def messageReceived(self, message):
 
        if message == 'PING':
 
            self.sendMessage('PONG')
 
            return
 
        log.info("got message from %r: %s", self.wsClient, message)
 
        p = Patch(jsonRepr=message)
 
        p.senderUpdateUri = self.wsClient.updateUri
 
        self.settings.db.patch(p)
 

	
 
liveClients = set()
light9/web/graph.coffee
Show inline comments
 
@@ -74,22 +74,33 @@ class window.SyncedGraph
 
  newConnection: ->
 
    fullUrl = 'ws://' + window.location.host + @patchSenderUrl
 
    @ws = new WebSocket(fullUrl)
 

	
 
    @ws.onopen = =>
 
      log('connected to', fullUrl)
 
      @resetStore()
 
      @pingLoop()
 

	
 
    @ws.onerror = (e) =>
 
      log('ws error ' + e)
 

	
 
    @ws.onclose = =>
 
      log('ws close')
 

	
 
    @ws.onmessage = (evt) =>
 
      if evt.data == 'PONG'
 
        return
 
      @onMessage(JSON.parse(evt.data))
 

	
 
  pingLoop: () ->
 
    if @ws.readyState == @ws.OPEN
 
      @ws.send('PING')
 
      
 
      clearTimeout(@_pingLoopTimeout) if @_pingLoopTimeout?
 
      @_pingLoopTimeout = setTimeout(@pingLoop.bind(@), 10000)
 

	
 
  onMessage: (msg) ->
 
    log('from rdfdb: ', msg)
 
    
 
    patch = {delQuads: [], addQuads: []}
 

	
 
    parseAdds = (cb) =>
0 comments (0 inline, 0 general)