zoukankan      html  css  js  c++  java
  • [NodeJS]基于WebSocket的NodeJS在线C/C++ WebIDE和在线编译

    很早以前,就想自己做一个在线的IDE,前段时间,做了一个NodeJS的简易版

    目前已经完成了登录、注册、代码编辑器(高亮、自动联想)、云端编译等功能

    前端我主要是使用Bootstrap、codemirror

    后端主要是NodeJS

    编译器是g++

    全站采用全静态,所以请求都是AJAX进行模拟

    下面是server.js的源码

    其他的可以移步coding查看项目

    https://git.coding.net/leeli73/CorCPP_Online_IDE.git

    因为很多文件的命名中,我使用了-,而coding中特殊字符不能作为文件名,所以项目中的www.zip 就是网站的前端代码

    server.js是服务器脚本

    还有很多问题,希望大奖能帮我一起找bug和完善功能

    var WebSocketServer = require('ws').Server,
        wss = new WebSocketServer({ port: 88 });
    
    wss.on('connection', function (ws) {
        console.log('client connected');
        ws.on('message', function (message) {
            console.log(message);
            ResponseJSON(message);
        });
    });
    
    function ResponseJSON(str)
    {
        var Data = JSON.parse(str);
        if (Data.Type == "Code") {
            Response_Code(Data.Data);
        }
        else if (Data, Type == "Get")
        {
    
        }
    }
    
    function Response_Code(code)
    {
        var fs = require("fs");
        fs.writeFile('gcccodecode.txt', code, function (err)
        {
            if (err)
            {
                return console.error(err);
            }
        })
        fs.readFile('gcccodecode.txt', function (err, data)
        {
            if (err)
            {
                return console.error(err);
            }
            console.log("DATA IS:" + data.toString());
        })
        var cmd = require("node-cmd");
        /*cmd.get('C:\Users\leeli\Documents\Visual Studio 2017\Projects\server\server\gcc\check.exe C:\Users\leeli\Documents\Visual Studio 2017\Projects\server\server\gcc\code\code.txt', function (data)
        {
            console.log(data);
        });*/
        cmd.run('E:serverservergcccheck.exe E:serverservergcccodecode.txt');
    
    }
  • 相关阅读:
    1006. 求和游戏
    1004. 西西弗斯式的命运
    1024. 排序
    1005. 数独
    kafka的基本操作
    kafka安装
    spring boot 使用redis 及redis工具类
    ArrayDeque类的使用详解
    设计模式随笔之——工厂方法模式
    转:Android随笔之——使用Root权限实现后台模拟全局按键、触屏事件方法(类似按键精灵)
  • 原文地址:https://www.cnblogs.com/lee-li/p/8654658.html
Copyright © 2011-2022 走看看