Giter Club home page Giter Club logo

websock's Introduction

websock

This library runs on nodejs engine, if you don't have it installed, please visit node.js.

Usage

'use strict';

var http = require('http');
var WebSocket = require('../lib/websocket');

// Create your own server
var server = http.createServer(function(request, response) {
  console.log((new Date()) + ' Received request for ' + request.url);
  response.writeHead(404);
  response.end();
});

server.listen(80, function() {
  console.log((new Date()) + ' Server is listening on port 80');
});

// Attached the server to websocket
var ws = new WebSocket({http: server});

ws
  .on('open', function (socket) {
    // This is called after connection has been established
  })
  .on('text', function (msg, socket) {
    // Handle text message here
  })
  .on('binary', function (msg, socket) {
    // Handle binary message here
  })
  .on('close', function (socket) {
    // Handle closing connection here
  })

Run demo

Go to the library page. And run command npm install to install all dependencies and and then run npm install -g gulp to install Gulp task runner.

Modify HOST at line 3 example/app.js to your localhost (DO NOT USE PORT 3000, it is for the website), example

  const HOST = 'ws://localhost:9000';

Run gulp serve to start serve, and open another terminal and run gulp web to start the web.

Getting To Know Yeoman

Yeoman has a heart of gold. He's a person with feelings and opinions, but he's very easy to work with. If you think he's too opinionated, he can be easily convinced. Feel free to learn more about him.

Created with

Yeoman and Generator-simple-package

License

MIT © NghiaTTran

websock's People

Contributors

nghiattran avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.