kiite

0.4.1 • Public • Published

npm npm npm

聞いて kiite 📞

simple long polling server and client

Easy to use

Server

var http = require( 'http' )
var server = http.createServer()

var kiite = require( 'kiite' )
var io = kiite( server )

io.on( 'connection', function ( socket ) {
  console.log( 'client connected! ' + io.clientsConnected )

  var name = 'anon' + Math.floor( Math.random() * 1000 )

  socket.emit( 'message', '[SERVER]: Welcome, ' + name + '!' )
  socket.broadcast( 'message', '[SERVER]: ' + name + ' joined.' )

  socket.on( 'message', function ( message ) {
    socket.broadcast( 'message', name + ': ' + message )
  } )

  socket.on( 'disconnect', function () {
    console.log( 'client disconnected. ' + io.clientsConnected )
  } )
} )

server.listen( 9090, function () {
  console.log( 'server listening at *:' + server.address().port )
} )

Client

<body>
  <h2>Kiite client</h2>
  <input type="text" id="input">
  <ul id="list"></ul>
  <script src="kiite.min.js" type="text/javascript"></script>
  <script type="text/javascript">
    var io = window.kiite.connect( { port: 9090 } )

    io.on( 'message', function ( text ) {
      var el = document.createElement( 'li' )
      el.innerHTML = text.trim()
      list.appendChild( el )
    } )

    input.focus()
    input.onkeyup = function ( evt ) {
      if ( evt.keyCode == 13 ) {
        io.emit( 'message', input.value )
        input.value = ''
      }
    }
  </script>
</body>

About

Small, quick, and easy sockets/longpolling for simple needs with no external dependencies, binaries or GYP rebuilds.

Why

Other rich solutions can be too bulky to justify their use for very simple needs with long downloads, install times, rebuilds, and may have cross platform inconsistencies.

How

Basic HTTP longpolling.

Alternatives

socket.io

socket.io-client

Test

npm test

Readme

Keywords

Package Sidebar

Install

npm i kiite

Weekly Downloads

3

Version

0.4.1

License

MIT

Unpacked Size

22.8 kB

Total Files

3

Last publish

Collaborators

  • talmobi