0.0.6 • Public • Published

    alt text

    Light, fast, easy to use, and auto-reconnecting if the internet drops. perfect for poor connection/pubilc WIFI and mobile devices.

    For this we use &

    We wanted to make sure also that the code you write on the server is the same as the code you write in the client/browser.

    alt text

    The setup of REWIRE allows you to hide server side code.

    For examples of in use today visit$tweet-dj-radio-app.php (Build you own Android/iPhone radio streaming appliction) and (A simple contact form).



    c.REWIRE.js & s.REWIRE.js dont not need to be altered just upload them to your public_html and they will handle all of your apps and bridge the transports.

    Connecting the server: This code can be found in n.example.js (start your app up with unix command node /location/n.example.js). This file points REWIRE to your severs main app script inside a folder you must create above public_html. The folders name is private_js as all javascript above the public_html directory is hidden from the public and protected.

    //require('location of s.REWIRE.js')('alow a client',[socket numbers],[port numbers],'main server script');

    Connecting the client: This code can be found in example.php. This is the page users will visit to view your app. It points REWIRE to your main clientside app script.

    var s={},S={},data={'nickname':nickname};
    //connect('server url',[socket numbers],[port numbers],data,'main client script');

    Now that you're all connected you are able to write the same code in both your client and your server (and soon in your

    Messaging using ws.send

    All these methods of sending have a 'func' part so you can give the message a name (like data parts can have as many key:values as you need.

    Talk to self



    Shout to all users including self


    Shout as a broadcast to all users


    Shout as a broadcast to all users in a room


    Shout as a broadcast to all users in a room relay from socket 0 to socket 4 (encoding param is needed for this)


    Message Events using ws.onmessage

    All custom events are listened to in the same way by adding them to the WHEN array and checking if they exist. if an event doesn't exist you get a nice console.dir showing everthing you missed just incase your sleepy.


    Don't pile up events, deleting them is easy!

    delete s[0].WHEN['func'];

    Rooms (Server side only)

    We like the concept of every app acting like a chat, so now we can SHOUT to a room if we want.

    Join a room


    Leave a room


    Multiple Sockets

    Sockets are an object s={}; So we can set up multiple that behave the same on both the client and the server.

    s[0] s[1] s[2] ...ect

    Each socket has its own wss server listening to its own port or you get EADDRINUSE (the error saying hey this port is alreay in use). nubers each socket to make sure that sockets don't interfear with each other and that they load in order.

    NOTE: For rooms and broadcasting only the first socket port is assigned a nickname. All others are called _port. This prevents getting the same message for each socket because each socket is otherwise seen as a client when broadcasting.

    Connecting Vs Reconnecting

    When the page is visited the server builds the client from a nickname in the address bar (this can easily be customised with extra vars or even getting stuff from a db).

    Then if your internet goes down, drops, server dies or whatever (normally you would need to refresh the web page)

    This way the client web page now trys to reconnect to the server every 2 seconds. when it reconnects the page remembers all user details, even what event listeners were set, and rejoins all the rooms the user was ocupying.

    Flash transport fallback

    Complete and stable.

    Flash API

    Must be the same experience as the current api. The functions that handle ws.onmessage and ws.send will probably be vey different but I wan't to style it in a way that the coder can just write apps the same as current client and browser code (all the same, nice and easy).

    I'm looking at this at the moment to see if I can get flash to talk to the net tcp part of ws. Help apprecieated.


    • Flash API

    Try Me Example

    1. upload c.REWIRE.js to your client site
    2. upload s.REWIRE.js to your server site
    3. n.example.js is started by node in ssh. In n.example.js edit your s.REWIRE.js location
    4. In n.example.js edit your policy file to accept your client site
    5. In n.example.js edit your socket number names
    6. In n.example.js edit your ports or open up ports 8004,8005 on your website
    7. In n.example.js name your js script for your main app code
    8. On your server in the directory above public_html make a folder called private_js and put your main script there
    9. get (check re.php script tags put them where you like)
    10. npm install jquery
    11. npm install json-stringify-safe
    12. npm install try-json-parse
    13. npm install ws
    14. npm install policyfile
    15. In example.php point to your server
    16. In example.php number your sockets
    17. In example.php name your ports
    18. In example.php point to your client main app code, this goes inside public_html
    19. In your browser navigate to
    20. Upload to your client public_html
    21. you may now write your own API events & commands in both and


    npm i

    DownloadsWeekly Downloads






    Last publish


    • avatar