protosock

Framework for building network protocols

npm install protosock
8 downloads in the last day
100 downloads in the last week
376 downloads in the last month

status

Information

Packageprotosock
Description Framework for creating websocket-based protocols
Node Version >= 0.6

ProtoSock uses ES5 features so be sure to include es5shim on your page.

Server Usage

ps = require 'protosock'
plugin =
  # Server default options
  options:
    namespace: 'TestProtocol'
    resource: 'default'

  # Called on server construct
  start: ->

  # Message formatters
  inbound: (socket, msg, done) -> done JSON.parse msg
  outbound: (socket, msg, done) -> done JSON.stringify msg

  # Validation
  validate: (socket, msg, done) -> done true
  invalid: (socket, msg) ->

  # Socket handlers
  connect: (socket) ->
  message: (socket, msg) ->
  error: (socket, err) ->
  close: (socket, reason) ->

options =
  resources: 'coolpath'

server = ps.createServer httpServer, plugin, options

Client Usage

plugin =
  # Client default options
  options:
    namespace: 'TestProtocol'
    resource: 'default'

  # Called on client construct
  start: ->

  # Message formatters
  inbound: (socket, msg, done) -> done JSON.parse msg
  outbound: (socket, msg, done) -> done JSON.stringify msg

  # Validation
  validate: (socket, msg, done) -> done true
  invalid: (socket, msg) ->

  # Socket handlers
  connect: (socket) ->
  message: (socket, msg) ->
  error: (socket, err) ->
  close: (socket, reason) ->

options =
  resources: 'coolpath'

client = ProtoSock.createClient plugin, options

Client Disconnect

This will disconnect the socket connection. By default the 'reconnect' option is set to true, so the client will immediately try to re-establish the connection.

client.disconnect()

Client Destroy

This will set 'reconnect' to false and then disconnect the socket. This results in a permanent disconnection, so it should be used for cleaning up unused clients. (e.g. in an automated test cleanup step)

client.destroy()

LICENSE

(MIT License)

Copyright (c) 2012 Fractal contact@wearefractal.com

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

npm loves you