Commit 724cddad authored by Neil Gershenfeld's avatar Neil Gershenfeld

start mods repo

parents

Too many changes to show.

To preserve performance only 1000 of 1000+ files are displayed.

This diff is collapsed.
File added
<html>
<head><meta charset="utf-8">
<title>mods</title>
</head>
<body link="black" alink="black" vlink="black">
<script src="js/mods.js"></script>
</body>
</html>
//
// echoserver.js
// WebSocket echo server
//
// Neil Gershenfeld
// (c) Massachusetts Institute of Technology 2016
//
// This work may be reproduced, modified, distributed, performed, and
// displayed for any purpose, but must acknowledge the mods
// project. Copyright is retained and must be preserved. The work is
// provided as is; no warranty is provided, and users accept all
// liability.
//
// check command line
//
if (process.argv.length < 4) {
console.log("command line: node echoserver.js client_address server_port")
process.exit(-1)
}
//
// start server
//
var client_address = process.argv[2]
var server_port = process.argv[3]
console.log("listening for connection from client address "+client_address+" on server port "+server_port)
var fs = require("fs")
var WebSocketServer = require('ws').Server
wss = new WebSocketServer({port:server_port})
wss.on('connection',function(ws) {
if (ws._socket.remoteAddress != client_address) {
console.log("connection rejected from "+ws._socket.remoteAddress)
wss.close()
process.exit(-1)
}
else {
console.log("connection accepted from "+ws._socket.remoteAddress)
}
ws.on("message",function(msg) {
//console.log(" "+msg)
ws.send(msg)
})
ws.on("close",function() {
console.log("connection closed")
})
})
//
// server.js
//
// Neil Gershenfeld
// (c) Massachusetts Institute of Technology 2016
//
// This work may be reproduced, modified, distributed, performed, and
// displayed for any purpose, but must acknowledge the mods
// project. Copyright is retained and must be preserved. The work is
// provided as is; no warranty is provided, and users accept all
// liability.
//
var server_port = '1234'
var client_address = '127.0.0.1'
console.log("listening for connections from "+client_address+" on "+server_port)
var server = {}
var WebSocketServer = require('ws').Server
wss = new WebSocketServer({port:server_port})
wss.on('connection',function(ws) {
if (ws._socket.remoteAddress != client_address) {
console.log("connection rejected from "+ws._socket.remoteAddress)
wss.close()
return
}
else {
console.log("connection accepted from "+ws._socket.remoteAddress)
}
ws.on('message',function(msg) {
//console.log('message: '+msg)
eval(msg)
})
})