Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

My sample server.js script to make multiples independent connections (solved) #94

Open
VigibotDev opened this issue Oct 9, 2015 · 0 comments

Comments

@VigibotDev
Copy link

(Sorry no static server because it served by Apache, I use reverse proxy with ws mod)
It work like "Anyterm" (new process and kill for each websocket cnx).

var io = require("socket.io").listen(82);
var pty = require("pty.js");

io.sockets.on("connection", function(socket) {
 var buff = [];

 var term = pty.spawn("/usr/bin/ssh", ["root@localhost"], {
  name: "xterm-256color",
  cwd: process.env.HOME,
  env: process.env
 });

 term.on("data", function(data) {
  return !socket ? buff.push(data) : socket.emit("data", data);
 });

 while(buff.length) {
  socket.emit("data", buff.shift());
 }

 socket.on("data", function(data) {
  term.write(data);
 });

 socket.on("resize", function(resize) {
  term.resize(resize.cols, resize.rows);
 });

 socket.on("disconnect", function() {
  socket = null;
  term.kill();
 });
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant