Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
* Copyright (c) 2016-2019 Moddable Tech, Inc.
*
* This file is part of the Moddable SDK.
*
* This work is licensed under the
* Creative Commons Attribution 4.0 International License.
* To view a copy of this license, visit
* .
* or send a letter to Creative Commons, PO Box 1866,
* Mountain View, CA 94042, USA.
*
*/
import {Server} from "websocket"
let server = new Server({port:80});
server.callback = function (message, value) {
switch (message) {
case Server.connect:
trace("main.js: socket connect.\n");
break;
case Server.handshake:
trace("main.js: websocket handshake success\n");
break;
case Server.receive:
trace(`main.js: websocket message received: ${value}\n`);
this.write(value); // echo
break;
case Server.disconnect:
#!/usr/bin/env teajs
/* simple websocket echo server: repeats received message to all clients (and logs to console) */
var Server = require("websocket").Server;
var ws = new Server("0.0.0.0", 8888, {idle:150});
var clients = [];
var app = {
onmessage: function(client, data) {
system.stdout.writeLine(data);
for (var i=0;i