Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

239
Vistas
How to create a terminal in the browser similar to replit.com

I am trying to create a terminal that you can use in a browser to run programs, similar to replit.com where you can run code in the browser and interact with the program. So far I've created a JS client and a Python server. The JS client looks like this:

var server = new WebSocket("ws://localhost:8001");

$(document).ready(function () {
  $("input").on("keydown", function search(e) {
    if (e.keyCode == 13) {
      server.send($(this).val());
    }
  });

  server.onmessage = function (event) {
    $("#result").append(event.data.replaceAll("\n", "<br>") + "<br>");
  };
});

Which connects to the server, sends all commands and receives all output.

The server looks like this:

#!/usr/bin/env python

import asyncio
import websockets
import subprocess


async def handler(websocket, _):
    while True:
        message = await websocket.recv()
        message = message.split()
        try:
            output = subprocess.run(
                [*message], stdout=subprocess.PIPE).stdout.decode('utf-8')
            await websocket.send(output)
        except:
            await websocket.send("Command error")


async def main():
    async with websockets.serve(handler, "", 8001):
        await asyncio.Future()

asyncio.run(main())

This works for running one off commands, but not if I want to run a Python program and interact with it. Is there any way for me to do that?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda