1.2.1 • Published 9 years ago

wyre v1.2.1

Weekly downloads
17
License
MIT
Repository
github
Last release
9 years ago

Build Status Join the chat at https://gitter.im/from-nibly/wyre

wyre

wyre is a websocket library that will change the way you use websockets. Wyre allows you to send messages that require a response message to be sent. Wyre also allows you to filter messages based on the type of message which you specify.

Getting Started

Server

var Server = require('wyre').Server;
var server = new Server();

//here we start the server
server.listen({ port : 1234}, function(err) {
    console.log('server is started!');
});

here we can listen for new connections

server.on('connection', function(connection) {
    console.log('connection recieved');
});

here we can listen for incoming messages

server.on('message', function(context) {
    console.log('got a message', context.message)
});

here we can listen for messages where the message type is a tweet

server.on('message', 'tweet', function(context) {
    console.log('got a tweet', context.message);
});

here we can listen for a request and reply to it

server.on('request', function(context) {
  console.log('got a request', context.message);
  context.reply({ answer : 'steve'});
});

Client

Clients are very similar but you connect to a server differently

var Client = require('wyre').Client;
var client = new Client();

//here we start the server
client.connect('ws://localhost:1234', function(err, connection) {
  if(err) {
    console.log('error connecting to the server', err);
  }
  else {
    console.log('client connected to server', connection);
  }
  //here we can send a message or a request;
  connection.send({ myNameIs : "bob" });
  connection.request({ question : "what is your name?"}, function(err, reply) {
    console.log('servers name is', reply.message.answer);
  });
});

Ready for more?

checkout our wiki!

or checkout our gitter channel for questions Join the chat at https://gitter.im/from-nibly/wyre

1.2.1

9 years ago

1.2.0

9 years ago

1.1.0

9 years ago

1.0.3

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago