This question ask exactly the same but have no answers
When on server side:
socket.write(Buffer.from("123"));
Then on client side:
recv(socket_fd, buffer, 3, 0);
connection stucks..
However
socket.end(Buffer.from("123"));
doesn't stuck the connection. And I understand why ( at least I think that I do ). But it closes the socket for reading on client side ( You still can send data ) So You need once again create new socket to read data.
Question: Is there a way to
socket.write(Buffer.from("something"))
and receive it on client side without
socket.end();
UPD: client side recv():
char *GetData(int socket_fd)
{
char init[] = {0x17, 0x22};
int bytes_read, n_reads = 0;
char *buffer = (char *)malloc(BUFFER_SIZE);
if (buffer == NULL)
{
puts("failed\n");
exit(EXIT_FAILURE);
}
send(socket_fd, init, 2, 0);
int offset = 0;
while ((bytes_read = recv(socket_fd, buffer + offset, BUFFER_SIZE, 0)) > 0)
{
if (bytes_read == -1)
{
puts("recv failed\n");
exit(EXIT_FAILURE);
}
offset += bytes_read;
char *tmp = realloc(buffer, offset + BUFFER_SIZE);
if (tmp == NULL)
{
puts("realloc failed\n");
exit(EXIT_FAILURE);
}
buffer = tmp;
}
return buffer;
}