mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 18:55:26 +00:00
added modules for work with socket.io
This commit is contained in:
parent
000fc9b6a3
commit
2f5178d4e7
3 changed files with 65 additions and 17 deletions
0
lib/client/Untitled
Normal file
0
lib/client/Untitled
Normal file
|
|
@ -1,17 +1,29 @@
|
|||
/* module make possible connectoin thrue socket.io on a client */
|
||||
var CloudCommander, io;
|
||||
var CloudCommander, io, socket;
|
||||
(function(){
|
||||
"use strict";
|
||||
var Util = CloudCommander.Util;
|
||||
|
||||
Util.jsload("http://localhost:31337/socket.io/lib/socket.io.js", function(){
|
||||
var socket = io.connect('http://localhost:31337/');
|
||||
socket.on('connect', function () {
|
||||
socket.send('hi');
|
||||
Util.jsload("http://localhost:31337/socket.io/lib/socket.io.js", {
|
||||
onload : function(){
|
||||
socket = io.connect(document.location.hostname);
|
||||
|
||||
socket.on('connect', function () {
|
||||
console.log('socket connected');
|
||||
});
|
||||
|
||||
socket.on('message', function (msg) {
|
||||
console.log(msg);
|
||||
});
|
||||
|
||||
socket.on('disconnect', function () {
|
||||
console.log('socket disconected');
|
||||
});
|
||||
},
|
||||
|
||||
socket.on('message', function (msg) {
|
||||
console.log(msg);
|
||||
});
|
||||
});
|
||||
onerror : function(){
|
||||
console.log('could not connect to socket.io\n'+
|
||||
'npm i socket.io');
|
||||
}
|
||||
});
|
||||
})();
|
||||
|
|
@ -1,13 +1,49 @@
|
|||
/* module make possible connectoin thrue socket.io on a server */
|
||||
|
||||
var CloudServer;
|
||||
var io = require('socket.io'),
|
||||
exec = require('child_process').exec,
|
||||
Socket = {};
|
||||
|
||||
var io = require('socket.io').listen(CloudServer.Server);
|
||||
/**
|
||||
* Function listen on servers port
|
||||
* @pServer {Object} started server object
|
||||
*/
|
||||
exports.listen = function(pServer){
|
||||
io = io.listen(pServer);
|
||||
|
||||
io.sockets.on('connection', function (socket) {
|
||||
Socket = socket;
|
||||
socket.send('hello from server!');
|
||||
|
||||
console.log('server connected');
|
||||
|
||||
socket.on('message', function(pCommand) {
|
||||
console.log(pCommand);
|
||||
|
||||
exec(pCommand, exec);
|
||||
});
|
||||
|
||||
});
|
||||
};
|
||||
|
||||
io.sockets.on('connection', function (socket) {
|
||||
socket.on('message', function (data) {
|
||||
console.log(data);
|
||||
});
|
||||
|
||||
socket.on('disconnect', function () { });
|
||||
});
|
||||
/**
|
||||
* function send result of command to client
|
||||
* @param error
|
||||
* @param stdout
|
||||
* @param stderr
|
||||
*/
|
||||
function exec(error, stdout, stderr) {
|
||||
if(stdout){
|
||||
console.log(stdout);
|
||||
Socket.send(stdout);
|
||||
}
|
||||
if(stderr){
|
||||
console.log('stderr: ' + stderr);
|
||||
Socket.send(stderr);
|
||||
}
|
||||
|
||||
if (error !== null) {
|
||||
console.log('exec error: ' + error);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue