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

如何在tcp发送数据后,直接自动关闭连接? #533

Closed
boybeak opened this issue Apr 22, 2024 · 1 comment
Closed

如何在tcp发送数据后,直接自动关闭连接? #533

boybeak opened this issue Apr 22, 2024 · 1 comment

Comments

@boybeak
Copy link

boybeak commented Apr 22, 2024

我看过了 #59 这个issue中的描述,有以下代码:

void connect_tcp_send(hloop_t* loop, char* ip, int port, char* message) {
    hio_t* client = hloop_create_tcp_client(loop, ip, port, on_connect, on_tcp_close);
    hio_write(client, message, strlen(message));
    hio_close(client);
}

希望达到的效果是,建立连接,发送message,然后立马断开连接。
但是实际上这样调用是做不到的,或者说是不能每次都把message发到服务端的,只有在on_connect中执行hio_write才可以,而且执行hio_write后,还不能立马调用hio_close,不然还是会收不到。按照 #59 的描述,应该是可以的,不知道是不是我哪里写错了?

@ithewei
Copy link
Owner

ithewei commented Apr 23, 2024

TCP客户端,需要在连接上以后才能开始发送数据,也就是on_connect回调通知你已经连接上了。

@ithewei ithewei closed this as completed May 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

2 participants