-
Notifications
You must be signed in to change notification settings - Fork 25
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
send_bytes in receive callback #18
Comments
Hi Rein, a couple of thoughts come to mind:
For reference, making the following changes to void ack_callback(async_comm::UDP &udp, const uint8_t* buf, size_t len)
{
char ack_message[] = "Acknowledge received";
udp.send_bytes(reinterpret_cast<uint8_t*>(ack_message), std::strlen(ack_message));
for (size_t i = 0; i < len; i++)
{
std::cout << buf[i];
}
}
int main()
{
// open UDP ports
async_comm::UDP udp1("localhost", 14620, "localhost", 14625);
udp1.register_receive_callback(std::bind(ack_callback, std::ref(udp1), std::placeholders::_1, std::placeholders::_2));
// ...
} |
You could also do it with a lambda capture, like this: async_comm::UDP udp1("localhost", 14620, "localhost", 14625);
std::function<void(const uint8_t*, size_t)> ack_callback = [&udp1](const uint8_t* buf, size_t len) {
char ack_message[] = "Acknowledge received\n";
udp1.send_bytes(reinterpret_cast<uint8_t*>(ack_message), std::strlen(ack_message));
for (size_t i = 0; i < len; i++)
{
std::cout << buf[i];
}
};
udp1.register_receive_callback(ack_callback); Or if the |
Hi @dpkoch , thanks for your quick response. It was a simple snippet so don't bother about scoped etc. I looked a little further and tried your example and it gives me the following output:
So the
No message is coming in here. I thought data was being received on the bind address/port and we are sending data to the remote address/port. Maybe I am totally misunderstandings things here .. Thanks again for your help! |
I think I've found the problem here: Line 107 in 12e172d
Is it logical to update the |
Hi,
I am trying to call the
send_bytes
method in a registeredreceive_callback
; however, the data is never sent. Am I doing something wrong or what could be the issue here?Setup:
Thanks,
Rein
The text was updated successfully, but these errors were encountered: