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

http doesn't get executed #528

Closed
Davevb opened this issue Mar 13, 2017 · 11 comments
Closed

http doesn't get executed #528

Davevb opened this issue Mar 13, 2017 · 11 comments

Comments

@Davevb
Copy link

Davevb commented Mar 13, 2017

When I execute nodeJs in cmd, it works. When I call it from c#, it doesn't

return function (tmpData, callback) {
var http = require('http');
var tmpResponse = 0;

            var options = {
                host: '<ipaddress>',
                path: '<path>',
                port: '30200'
            };

            http.get(
                options,
                function (response) {
                    var str = ''
                    response.on('data', function (chunk) {
                        str += chunk;
                    });

                    response.on('end', function () {
                        console.log(str);
                        tmpResponse = 1
                        callback(null, 'tmpResponse: ' + tmpResponse);
                    });
                }
            );
        }
@soft-techP
Copy link

Same issue with me.
I have very simple node js code. It only does a http request.
This is the code file (req1.js):

var http = require('http');

var options = {
  host: '10.10.60.1',
  port: '30200',
  path: '/api/v1/action/action?id=572&actionType=TOGGLE&delayOn=00:00:00&delayOff=00:00:00'
};
http.request(options).end();

Executing this file through cmd (>node req1.js) works perfectly.

Now when trying to execute this file though edje.js from within a console application, it doesn't work.
c# code:

using System;
using System.Threading.Tasks;
using EdgeJs;

class Program
{
    public static async Task Start()
    {
        var func = Edge.Func(@" 
            var http = require('http');

            var options = {
                host: '10.10.60.1',
                port: '30200',
                path: '/api/v1/action/action?id=572&actionType=TOGGLE&delayOn=00:00:00&delayOff=00:00:00'
            };

            return function (data, callback) {
                http.request(options).end();
                callback(null, 'Node.js reply ' + data);
            }
        ");

        Console.WriteLine(await func("test"));
    }

    static void Main(string[] args)
    {
        Start().Wait();
    }
}

The http.request is not working !
I hope that someone can help me, or give me a hint to look further.
thanks

@soft-techP
Copy link

Anyone an idea?

@dpolivy
Copy link
Contributor

dpolivy commented May 7, 2017

This may be related to #325. See if the latest release (edge@7.10.0) fixes the problem and report back!

@soft-techP
Copy link

@dpolivy Updated to edge@7.10.0 but still not working. Only thing I want to do is calling a http request. See code above. I hope you can help me.

@dpolivy
Copy link
Contributor

dpolivy commented May 11, 2017

@soft-techP Are you using the NuGet package, or the actual npm module? I have a feeling the bits in the NuGet package were not properly updated with the fix.

@Davevb
Copy link
Author

Davevb commented May 11, 2017

The crazy thing is, when I add setTimeout(function (){ }, 1); as last line of code, it works...

@dpolivy
Copy link
Contributor

dpolivy commented May 11, 2017

@Davevb That sounds exactly like the issue solved in #325. I think the NuGet package needs to be updated. @tjanczuk will check it tonight.

@soft-techP
Copy link

@dpolivy I'm using the NuGet package. Workaround from with setTimeout(function (){ }, 1); from @Davevb works for me too. Though I find this very strange.

@dpolivy
Copy link
Contributor

dpolivy commented May 20, 2017

@Davevb @soft-techP OK, update NuGet package is available which includes the right bits to fix the async problem. I think this should address the problem for you. Give them a try!

https://www.nuget.org/packages/Edge.js/7.10.1

@soft-techP
Copy link

@dpolivy Tested this new version and it works! Thanks very much for your help.

@dpolivy
Copy link
Contributor

dpolivy commented May 22, 2017

@soft-techP Awesome! Glad we got this figured out.

@agracio agracio closed this as completed Jun 15, 2024
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

4 participants