70 lines
1.7 KiB
JavaScript
70 lines
1.7 KiB
JavaScript
|
|
//var ws = require("nodejs-websocket")
|
||
|
|
//
|
||
|
|
//// Scream server example: "hi" -> "HI!!!"
|
||
|
|
//var server = ws.createServer(function (conn) {
|
||
|
|
// console.log("New connection")
|
||
|
|
// conn.on("text", function (str) {
|
||
|
|
// console.log("Received "+str)
|
||
|
|
// conn.sendText(str)
|
||
|
|
// })
|
||
|
|
// conn.on("close", function (code, reason) {
|
||
|
|
// console.log("Connection closed")
|
||
|
|
// })
|
||
|
|
//}).listen(8080)
|
||
|
|
|
||
|
|
var WebSocketServer = require('ws').Server
|
||
|
|
, wss = new WebSocketServer({port: 8080});
|
||
|
|
wss.on('connection', function(ws) {
|
||
|
|
ws.on('message', function(message) {
|
||
|
|
console.log('received: %s', message);
|
||
|
|
ws.send(message);
|
||
|
|
});
|
||
|
|
//ws.send(message);
|
||
|
|
});
|
||
|
|
|
||
|
|
//var http = require('http'),
|
||
|
|
//io = require('socket.io'),
|
||
|
|
//server = http.createServer(function(req, res){
|
||
|
|
// //res.writeHeader(200, {'Content-Type': 'text/html'});
|
||
|
|
// //res.writeBody('Hello world');
|
||
|
|
// //res.finish();
|
||
|
|
//});
|
||
|
|
//server.listen(8080);
|
||
|
|
//var socket = io.listen(server);
|
||
|
|
//socket.on('connection', function(client){
|
||
|
|
// client.on('message', function(message){
|
||
|
|
// savePosition(message);
|
||
|
|
// });
|
||
|
|
// client.on('disconnect', function(){});
|
||
|
|
//});
|
||
|
|
|
||
|
|
|
||
|
|
//var net = require('net');
|
||
|
|
//var mySocket;
|
||
|
|
//
|
||
|
|
//// create the server and register event listeners
|
||
|
|
//var server = net.createServer(function(socket) {
|
||
|
|
// mySocket = socket;
|
||
|
|
// mySocket.on("connect", onConnect);
|
||
|
|
// mySocket.on("data", onData);
|
||
|
|
//});
|
||
|
|
//function onConnect()
|
||
|
|
//{
|
||
|
|
// console.log("Connected to Flash");
|
||
|
|
//}
|
||
|
|
//function onData(d)
|
||
|
|
//{
|
||
|
|
// if(d == "exit\0")
|
||
|
|
// {
|
||
|
|
// console.log("exit");
|
||
|
|
// mySocket.end();
|
||
|
|
// server.close();
|
||
|
|
// }
|
||
|
|
// else
|
||
|
|
// {
|
||
|
|
// console.log("From Flash = " + d);
|
||
|
|
// mySocket.write(d);
|
||
|
|
// }
|
||
|
|
//}
|
||
|
|
//
|
||
|
|
//server.listen(8080);
|