1

So I have my Raspberry Pi currently running a unix socket with the library and if I make a simple get request in my browser like 10.0.0.200:2500 I get the response message I want (just a string of text). I also get the same result using PostMan so I KNOW the socket is working find.

The issue is when I am using Node.js to make this same request with

var options = {
  host: '10.0.0.200',
  port: 2500,
  path: '/'
};

http.get(options, function(res) {
  console.log("Got response: " + res.statusCode);
}).on('error', function(e) {
  console.log("Got error: " + e.message);
});

I keep getting a { [Error: Parse Error] bytesParsed: 0, code: 'HPE_INVALID_CONSTANT' } message in node

My socket is also showing

GET / HTTP/1.1
Host: 10.0.0.200:2500
Connection: close

So Idk why the conneciton is closed and I even tried sending a header with connection : keep-alive and that didn't help either

6
  • 2
    If you're specifying a host and port, you're not connecting over a unix socket, you're connecting over TCP. Commented Aug 7, 2016 at 8:24
  • Does the server app running on port 2500 return a proper HTTP response? If not, you don't want to use http, but net. Commented Aug 7, 2016 at 8:26
  • What is serving the responses? Is the source code available? Have you ran tcpdump to verify that the server is responding with a well-formed HTTP response? Commented Aug 7, 2016 at 8:27
  • @robertklep How would I used .net since I need to specify the IP, I am trying to connect from node on a different machine like I was with the other Get request Commented Aug 7, 2016 at 8:31
  • 1
    @FrickeFresh net.connect(). Commented Aug 7, 2016 at 8:32

1 Answer 1

1

Thanks to @roberklep

I got it work using net.connect() and passing the options argument found here net.connect()

also another good source for example of use here

Sign up to request clarification or add additional context in comments.

1 Comment

I had the same issue with another service. This helped me get net.connect() working. I also needed to write the correct HTTP request in the connect callback, following this example: github.com/nodejs/node-v0.x-archive/issues/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.