How to use the websocket.Server function in websocket

To help you get started, we’ve selected a few websocket examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Moddable-OpenSource / moddable / examples / network / websocket / websocketserver / main.js View on Github external
* 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");

		case Server.handshake:
			trace("main.js: websocket handshake success\n");

		case Server.receive:
			trace(`main.js: websocket message received: ${value}\n`);
			this.write(value);		// echo

		case Server.disconnect:
github ondras / TeaJS / example / websocket.js View on Github external
#!/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("", 8888, {idle:150});

var clients = [];
var app = {
	onmessage: function(client, data) {
		for (var i=0;i