简体   繁体   English

Boost Asio:关于本教程的一些问题(同步日间服务器/客户端)

[英]Boost Asio: Some questions about the tutorial (A synchronous daytime server/client)

I'm trying to work with Boost Asio instead of RakNet so I was trying to follow along with the examples on the Boost website but I have some questions left unanswered. 我正在尝试使用Boost Asio而不是RakNet,所以我试图跟随Boost网站上的示例,但我有一些问题没有得到答复。 Here's the link: http://www.boost.org/doc/libs/1_55_0/doc/html/boost_asio/tutorial/tutdaytime1.html 这是链接: http//www.boost.org/doc/libs/1_55_0/doc/html/boost_asio/tutorial/tutdaytime1.html

Just a heads up, I got the tutorial working, both the client and the server. 只是抬头,我得到了教程,客户端和服务器。

1) Why does the query need the string "daytime"? 1)为什么查询需要字符串“daytime”? It's nowhere to be found in the server setup. 在服务器设置中找不到它。 The client only seems to connect when I'm using that string. 当我使用该字符串时,客户端似乎只是连接。 (Tried with "test" and it didn't connect) (试过“测试”并没有连接)

2) Why don't I need to give the client a port to connect to? 2)为什么我不需要为客户端提供连接端口? Does it search for this port itself or is there and option to set this up manually as well? 它是否会搜索此端口本身,还是可以选择手动设置此端口?

Thanks in advance. 提前致谢。

    tcp::resolver::query query(argv[1], "daytime");

This lines resolves an endpoint, where argv[1] is the host, and "daytime" represents the port . 这一行解析了一个端点,其中argv[1]是主机, "daytime"代表端口 Yeah, that's a little surprising, as you'd expect something like 80 or 443 there. 是的,这有点令人惊讶,因为你期望那里有80443这样的东西。 However, what you see is the service-name which (like hostnames) can be used instead of a hardcoded port, and gets resolved by the operating system. 但是,您看到的是可以使用服务名称 (如主机名)而不是硬编码端口,并由操作系统解析。

If hostnames are resolved via /etc/hosts , services are resolved via /etc/services (or C:\\WINDOWS\\system32\\drivers\\etc\\services I suppose). 如果通过/etc/hosts解析/etc/hosts ,则通过/etc/services (或者我认为是C:\\WINDOWS\\system32\\drivers\\etc\\services )解析C:\\WINDOWS\\system32\\drivers\\etc\\services

On my system this file contains: 在我的系统上,此文件包含:

daytime     13/tcp
daytime     13/udp

So, in fact you could just use "13" instead of "daytime" . 所以,实际上你可以使用"13"而不是"daytime" Note that this is the default port for the system daytime service . 请注意,这是系统日间服务默认端口。 It "works" because your system answers on that port. 它“有效”,因为您的系统在该端口上应答。 (Or because your server is already running and uses that port, I don't know which server you run and how :)) (或者因为您的服务器已经运行并使用该端口,我不知道您运行的服务器以及如何:))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Boost Asio UDP白天服务器异步接收 - Boost Asio UDP Daytime Server Async receive Boost :: Asio同步客户端超时 - Boost::Asio synchronous client with timeout 无法获得boost :: asio简单的同步服务器教程程序工作 - 连接被拒绝 - Cannot get boost::asio simple synchronous server tutorial program to work — connection refused 同步TCP日间客户端的用法 - usage of A synchronous TCP daytime client 增强Asio多线程TCP同步服务器 - Boost Asio Multithreaded TCP Synchronous Server 通过Boost Asio的async_read_some回调函数向服务器发出有关用户-客户端错误的信号 - Signal server about user-client error from Boost Asio's async_read_some callback function boost daytime7服务器示例不响应netcat客户端 - boost daytime7 server example doesn't respond to netcat client Boost ASIO 异步 TCP 日间服务器示例失败,响应超过 65536 字节时出现“对等连接重置” - Boost ASIO Asynchronous TCP daytime server example fails with "Connection reset by peer" on responses over 65536 bytes 需要对同步与异步 asio 操作进行一些说明 - Some clarification needed about synchronous versus asynchronous asio operations C++ boost asio:带有 boost:asio::read 和 boost::asio::write 的简单服务器/客户端传递一个 int 向量 - C++ boost asio : simple server/client with boost:asio::read and boost::asio::write passing a vector of int
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM