# vi-websocket

> A websocket framework for mobile web apps.

Latest version **0.0.2** (published 2015-02-12) · 0 weekly downloads

## Install

```sh
npm install vi-websocket
pnpm add vi-websocket
yarn add vi-websocket
bun add vi-websocket
```

## Health

**Score 10/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; low quality score; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.2 |
| Published | 2015-02-12 |
| First published | 2015-01-08 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | Sun Haohao |
| Maintainers | viringbells |

## Links

- npm: https://www.npmjs.com/package/vi-websocket
- Repository: h
- npm.io page: https://npm.io/package/vi-websocket

## Dependencies (1)

- [extend](https://npm.io/package/extend.md) 2.0.0

## Recent versions

- 0.0.2 (latest) — 2015-02-12
- 0.0.1 — 2015-01-27
- 0.0.0 — 2015-01-08

## README

# vi-websocket
A websocket framework for mobile web apps.

## Get Started
For the most common case, you can start a websocket server by creating a websocket server just like using http module.

    var ws = require('vi-websocket');
    ws.createServer(function(client, request){
        //Handle the connection with client and request
    }).listen(8023, function(){
        console.log("Listening for websocket connections on port 8023 ...");
    }

The arg `client` is an instance of `Client` which encapsulate an instance of `net.Socket` to handle the details of communication with websocket protocal. Typically, `client.on('message',on_message)` is used to handle each message from the browser. `client.send(message)` is used to send message to the browser.

    var ws = require('vi-websocket');
    ws.createServer(function(client, request){
        console.log("A connection has established");
        client.send("Welcome to my site!");
        client.on('message',function(msg){
            console.log("A message received : " + msg);
            client.send("I have received your message : " + msg);
        });
    }).listen(8023, function(){
        console.log("Listening for websocket connections on port 8023 ...");
    });

Then you can start a new websocket connection on the browser:

    var ws = new WebSocket("ws://localhost:8023/");
    ws.onmessage = function(e){
        console.log("Data received : " + e.data);
    };
    ws.onopen = function(){
        ws.send("Nice to meet you, my name is Jack");
    }

## To Be Continued ...

---
_Source: https://npm.io/package/vi-websocket · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
