c ++套接字编程与url:port / url在getaddrinfo [英] c++ socket programming with url:port/url in getaddrinfo

查看:281
本文介绍了c ++套接字编程与url:port / url在getaddrinfo的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

解决c ++和相当新的插座。我有一个python应用程序正确连接和一个工作的.net应用程序。

Relearning c++ and fairly new to sockets. I have a python app that connects properly and a .net app that works.

我不知道的是我需要调用的网址是www.domain.com:8080/signalr
Calling www.domain.com/ signalr:8080将无法工作。

What I can't figure out is the url I need to call is www.domain.com:8080/signalr Calling www.domain.com/signalr:8080 will not work.

按照似乎是一个标准的例子:
http://beej.us/guide/bgnet/output/html/multipage/clientserver.html#simpleserver

Following what seems to be a standard example: http://beej.us/guide/bgnet/output/html/multipage/clientserver.html#simpleserver

无论我尝试什么,我得到的名字或服务未知。

No matter what I try, I get name or service unknown.

if ((rv = getaddrinfo("http://www.Domain.com:8080/signalr", PORT, &hints, &servinfo)) != 0) {



<只是试图找出如何调用正确的URL。

tried leaving PORT null. Just trying to figure out how to call the correct url.

这是运行在raspbian(debian)如果这很重要。

And this is running on raspbian(debian) if that matters.

任何建议将非常感谢。

Any suggestions would be greatly appreciated.

推荐答案

getaddrinfo()它不实现HTTP协议。此外,它不知道如何解析网址,您必须自己这样做。

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.

正确的呼叫将是:

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

这将返回正确的 struct sockaddr * 调用 connect()并执行所有的套接字。

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

如果你想要一个函数, HTTP协议为你,你将需要一个更高级的库。我建议 libcurl

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

这篇关于c ++套接字编程与url:port / url在getaddrinfo的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆