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

Embeded nodejs in Win32 application #585

Closed
823639792 opened this issue Apr 17, 2017 · 9 comments
Closed

Embeded nodejs in Win32 application #585

823639792 opened this issue Apr 17, 2017 · 9 comments
Assignees

Comments

@823639792
Copy link

823639792 commented Apr 17, 2017

@refack

node version: 7.8.0
platform: windows7

I want to embed nodejs in my application.
but when I use http interface throw exception:

function getServerFileContent(url, sb, fb){
	var http = global.require('http');
	var buffer = new Buffer("");
	var list = [];
	var request = http.get(url, function (res) {
		res.on('data', function (data) {
			list.push(data);
		}).on('end', function (data) {
			buffer = Buffer.concat(list);
			sb(url, buffer);
		}).on("error", function(data){
			fb(url);
		});
	});
	request.on("error", function(){
		fb(url);
	})
}

getServerFileContent("http://www.xxxxx.com/base.js", function(url, data){console.log(url, data.toString())});
_http_outgoing.js:721 Uncaught TypeError: socket.cork is not a function
    at ClientRequest._flushOutput (_http_outgoing.js:721)
    at ClientRequest._flush (_http_outgoing.js:700)
    at _http_client.js:249
    at callSocketMethod (_http_client.js:656)
    at ClientRequest.onSocket (_http_client.js:661)
    at Object.onceWrapper (events.js:293)
    at emitOne (events.js:96)
    at ClientRequest.emit (events.js:191)
    at tickOnSocket (_http_client.js:622)
    at onSocketNT (_http_client.js:638)
@823639792
Copy link
Author

823639792 commented Apr 17, 2017

in stdio.js I create dummy stream.

var dummyOutput = true;
var W = require('_stream_writable');
var R = require('_stream_readable');
var util = require('util');
util.inherits(DummyWritableStream, W);
util.inherits(DummyReadableStream, R);

var fs = require("fs");
var log = fs.createWriteStream('c:\\log.txt', { 'flags': 'a' });

function DummyWritableStream() {
    W.apply(this, arguments);
    this.buffer = [];
    this.written = 0;
}

function DummyReadableStream() {
    R.apply(this, arguments);
    this.buffer = [];
    this.reading = false;
}

DummyWritableStream.prototype._write = function (chunk, encoding, cb) {
    //this.buffer.push(chunk.toString());
    //this.written += chunk.length;
    log.write(chunk);
    cb();
};
DummyReadableStream.prototype._read = function (param) {
    log.write("_read");
}

function createWritableDummyStream(fd) {
    var stream = new DummyWritableStream();
    stream.fd = fd;
    stream._isStdio = true;
    stream.isTTY = false;
    return stream;
}

function createReadableDummyStream(fd) {
    var stream = new DummyReadableStream();
    stream.fd = fd;
    stream._isStdio = true;
    stream.isTTY = false;
    stream.readable = false;
    return stream;
}

@refack refack self-assigned this May 5, 2017
@refack
Copy link

refack commented May 5, 2017

@823639792 Sorry thing dropped off my radar... Back in focus.
Did you make any progress?

@kanbang
Copy link

kanbang commented Jun 27, 2017

how to embed nodejs in win32 non-console application (for example:mfc)?
could someone kind show me a tiny demo

@gireeshpunathil
Copy link
Member

Many design elements of node.js assume that it is a console application. Examples: REPL, standard streams, parent-child communication channels, and the Console object itself. I am not sure it can be embedded into an MFC application without making fair amount of refactoring.

@823639792
Copy link
Author

823639792 commented Jul 11, 2017

I embed nodejs in my mfc application, but inspect by chrome or some other conditions, it will crash.
I modified many source code:
1、stream(stdio.js)
2、inspector
3、Console
4、Run a timeInterval to keep thread;
I suggest you embed V8, or reference nw.js.
@kanbang

@refack
Copy link

refack commented Jul 11, 2017

nodejs/node#14158 - to try to raise focus on the embedding story

@kanbang
Copy link

kanbang commented Jul 23, 2017

@823639792
I had embed v8 in a draw toolbox, since already using V8, why not embed node.js instead? This would allow developers to use any of the 100,000+ packages in npm without restriction.
image

could you help me to build a tiny mfc demo, just a helloworld, win32 non-console, without child process

@styfle
Copy link
Member

styfle commented Mar 19, 2018

@refack @Trott Should this ticket be closed in favor of nodejs/node#14158 ?

@Trott
Copy link
Member

Trott commented Mar 19, 2018

@refack @Trott Should this ticket be closed in favor of nodejs/node#14158 ?

Closing. If anyone thinks it should remain open, leave a comment (or re-open it if GitHub let's you). Thanks!

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

6 participants