0

Relearning C++ and fairly new to sockets. I have a Python app that connects properly and a .NET app that works.

The URL I need to call is domain.com:8080/signalr. I'm following what seems to be a standard example, e.g.:

if ((rv = getaddrinfo("www.domain.com", PORT, &hints, &servinfo)) != 0) {

...but no matter what I try, I get name or service unknown.

  • Calling domain.com/signalr:8080 will not work.
  • I tried leaving PORT null

This is running on Raspbian (Debian) if that matters.

Any suggestions would be greatly appreciated.

Scott Smith
  • 3,900
  • 2
  • 31
  • 63
VirtualLife
  • 402
  • 5
  • 14

1 Answers1

4

What getaddrinfo() does is name resolution. It does not implement the HTTP protocol. Also, it does not know how to parse the URL, you have to do that yourself.

The right call would be something along the lines of:

getaddrinfo("www.Domain.com", "8080", ...);

And that will return the right struct sockaddr* to call connect() and do all the socket stuff.

If you want a function that does all the HTTP protocol for you, you'll need a higher level library. I recommend libcurl.

rodrigo
  • 94,151
  • 12
  • 143
  • 190
  • I understand it doesn't implement the HTTP protocol, unfortunately I can't easily change the URL to be called (not even sure if I can). I have used libcurl a little, are you saying I can somehow integrate that with getaddrinfo to be able to call the correct url? – VirtualLife May 09 '14 at 20:01
  • @VirtualLife: No, `getaddrinfo()` calls nowhere, it just solves the host name and gives you the IP address. Well, it calls DNS, but that doesn't count. What I don't understand is why you insist on using `getaddrinfo()` with a URL, that will never work. – rodrigo May 09 '14 at 20:20
  • Gotcha, I guess I was misunderstanding what it did. I thought it was the piece that built the connection, but I guess not. I will do some more research on it. Thanx for your help. – VirtualLife May 09 '14 at 20:33
  • Can do it like this too (manually) http://ideone.com/lAovHH Just needs proper checks for reading/writing. – Brandon May 09 '14 at 21:48