Weitere ähnliche Inhalte
Ähnlich wie Socket.io under the hood (20)
Kürzlich hochgeladen (20)
Socket.io under the hood
- 6. Why don’t we use websocket?
● Standardized by
○ RFC 6455
○ W3C
● IE9 says NO
- 10. API
# client
socket.emit(‘foo’, param1, param2, ...)
socket.on ‘bar’, (param1, param2, ...) ->
console.log(‘yay got a bar!’)
# server
socket.on ‘foo’, (param1, param2, ...) ->
console.log(‘yay got a foo!’)
socket.emit(‘bar’, param1, param2, ...)
- 11. Packet
socket.emit(‘foo’, param1, param2, ...)
# socket.io v0.9.x
packet = {
type: ‘event’
id: ‘unique packet id’
name: ‘foo’
args: [param1, param2, ...]
}
# socket.io v1.0.x
packet = {
type: ‘event’
id: ‘unique packet id’
name: ‘foo’
data: [param1, param2, ...]
}
https://github.com/LearnBoost/socket.io-protocol
- 12. Communication Layer
# socket.io v0.9.x
packet = {
type: ‘event’
id: 1
name: ‘foo’
args: [param1, param2, ...]
}
# socket.io v0.9.x
5:1::{“name”:”foo”,”args”:[param1, param2, ...]}
https://github.com/LearnBoost/socket.io-spec