New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client.onError doesn't triggered when there is no connection/server #6

Closed
selimanac opened this Issue Oct 7, 2018 · 4 comments

Comments

Projects
None yet
2 participants
@selimanac

selimanac commented Oct 7, 2018

When server is not available, onError message "mostly" doesn't triggered. Sometimes it works when I build and then rebuild the project, but I couldn't find any clue or pattern about this. It is possible that other dependencies cause this or maybe built in cache of Defold.

This is the client output when there isn't any server and onError doesn't triggered :

{
  roomStates = {
  }
  roomsAvailableRequests = {
  }
  requestId = 0,
  on = function: 0x0a1b70e0,
  connection = {
    emit = function: 0x0aaf9d60,
    _enqueuedCalls = {
    }
    on = function: 0x0aaf9d80,
    is_html5 = false,
    off = function: 0x0aaf9f40,
    _on = {
      close = {
        1 = function: 0x0aafa1f0,
      }
      error = {
        1 = function: 0x0aafa140,
      }
      message = {
        1 = function: 0x0aafa180,
      }
      open = {
        1 = function: 0x0aafa0a0,
      }
    }
    state = CLOSED,
    listeners = function: 0x0aaf9d40,
    endpoint = ws://localhost:8080/?colyseusid=xmjmMr3lo,
  }
  rooms = {
  }
  hostname = ws://localhost:8080/,
  connectingRooms = {
  }
  _on = {
  }
  emit = function: 0x0a1b7210,
  listeners = function: 0x0a1b71f0,
  off = function: 0x0a1b7100,
  id = xmjmMr3lo,
}

There isn't any server and onError triggered :

{
  roomStates = {
  }
  roomsAvailableRequests = {
  }
  requestId = 0,
  on = function: 0x12f4f0e0,
  connection = {
    ws = {
      step = function: 0x13892d10,
      sock_close = function: 0x13892860,
      on_close = function: 0x13892880,
      send = function: 0x13892c30,
      on_disconnected = function: 0x13892d70,
      sock = tcp{client}: 0x13893630,
      sock_send = function: 0x138928a0,
      close = function: 0x13892cc0,
      on_connected = function: 0x13892d50,
      on_message = function: 0x13892d30,
      connect = function: 0x138929f0,
      state = CLOSED,
      sock_connect = function: 0x13892830,
      sock_receive = function: 0x138928c0,
      receive = function: 0x13892c80,
    }
    emit = function: 0x13891d60,
    _enqueuedCalls = {
    }
    on = function: 0x13891d80,
    is_html5 = false,
    off = function: 0x13891f40,
    _on = {
      close = {
        1 = function: 0x138921f0,
      }
      error = {
        1 = function: 0x13892140,
      }
      message = {
        1 = function: 0x13892180,
      }
      open = {
        1 = function: 0x138920a0,
      }
    }
    state = CONNECTING,
    listeners = function: 0x13891d40,
    endpoint = ws://localhost:8080/?colyseusid=xmjmMr3lo,
  }
  rooms = {
  }
  hostname = ws://localhost:8080/,
  connectingRooms = {
  }
  _on = {
  }
  emit = function: 0x12f4f210,
  listeners = function: 0x12f4f1f0,
  off = function: 0x12f4f100,
  id = xmjmMr3lo,
}

@selimanac

This comment has been minimized.

selimanac commented Oct 7, 2018

I just test the defold-websocket and I can confirm that it works as expected.

ws:on_connected() returns an error with 'closed'.

@selimanac

This comment has been minimized.

selimanac commented Oct 7, 2018

Also ws:on_connected returns 'closed' on colyseus (connection.lua)

self.ws:on_connected(function(ok, err)
    self.state = self.ws.state
    
    if err then
      pprint(err) -- <- returns closed
      self:emit('error', err)
      self:close()
@endel

This comment has been minimized.

Member

endel commented Oct 8, 2018

Hey @selimanac,

The same thing happened to me recently (I believe). The colyseus.client tries to connect immediately upon instantiation, and it emits the "error" callback before you actually start listening to it.

To fix this, I've added a second argument not to connect immediately, and later you manually tell the client to connect. Let me know if this works for you:

client = Colyseus.new("ws://yourendpoint:1234", false) -- false as second argument

client:on("open", function()
	print("client: CONNECTED")
end)

client:on("closed", function()
	print("client: DISCONNECTED")
end)

client:on("error", function(e)
	print("ERROR: " .. tostring(e))
end)

client:connect() -- manually connect after registering the listeners
@selimanac

This comment has been minimized.

selimanac commented Oct 8, 2018

Thank you @endel work like a charm.

@selimanac selimanac closed this Oct 8, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment