Currently, I use libevent
to send and receive messages. The issue I am currently encountering is that I do not receive all messages on the server; and only receive the first message I sent.
Client Code:
for (int i=0; i < 10 ; i++)
{
bufferevent_write(bev, data, strlen(data) + 1);
}
Server Code:
static void read_cb(struct bufferevent* bev, void* arg)
{
char buf[2048] = {};
bufferevent_read(bev, buf, sizeof(buf));
//do something
}
I have modified the client like this:
for (int i=0; i < 10 ; i++)
{
bufferevent_write(bev, data, strlen(data) + 1);
sleep(1)
}
When I add a sleep(1)
,I can receive all messages.
I would like to avoid using sleep(1)
. What needs to be added / changed in code, such that all messages can be received, and sleep
is not used.