Giter Club home page Giter Club logo

moai's Introduction

MOAI ๐Ÿ—ฟ

Client-to-server connection wrapper

This library is a wrapper around the WebSocket API for use with Node.JS and web applications. There is also a lite version that uses raw TCP sockets for client-to-server communication rather than the websocket protocol.

Example (WebSocket)

server.js (Node.JS server-side)

const Server = require('./server');
const server = new Server();

server.on('client', client => {
  
  client.on('packet', data => {
    // Handle data from client
  });
  
  client.on('disconnect', event => {
    // Handle client disconnect
  });
  
});

server.listen({ port: 8080, path: '/ws' });

index.html (HTML client-side)

<!DOCTYPE html>
<head>
  <!-- Serializer has to be imported in html manually
  and must be a global variable. For example, moai uses
  a custom serializer although you could customize that
  by exporting Serializer#encode() and Serializer#decode()
  functions of your own.
  -->
  <script src="./serializer.js">
  <!-- Moai client-side import -->
  <script src="./client.js">
  <script>
    // Client-side code.
    let client = new Client();
    
    client.connect(new URL("ws://127.0.0.1:8080/ws"), connected => {
      if(connected) {
        // Connected
        
        client.on('packet', data => {
          // Handle data from server
        });
        
        client.on('disconnect', event => {
          // Handle disconnect
        });
        
      } else {
        // Connection failed
      }
    });
    
  </script>
</head>

Why moai?

  • Easy to use
  • Allows transmission of JSON

Moai-Web VS Moai-Lite

Moai-Web Moai-Lite
Protocol TCP
Serializer SimpleSerializer
Web Support โœ… Requires custom solution
Raw TCP Socket support โŒ โœ…

Download (latest):

moai's People

Contributors

z3db0y avatar

Watchers

 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.