我用C写了一个小 SocketWrapper只是为了学习,它可以工作。我正在发送一个 GET 请求并接收一个缓冲区 [1024]。但是我想阅读的内容往往比1024长,如何确定长度并接收整个数据?
#include <stdio.h>
#include <stdbool.h>
#include "lib/output.h"
#include "lib/network.h"
int main(int argc, char *argv[]) {
debug_verbose = true;
struct IPv4_CLIENT client;
client = socketIPv4("google.com", 80);
if(socketIPv4_connect(client) < 0) {
error("Connect failed!");
return -1;
}
char send_buffer[256];
bzero(send_buffer, 256);
printline("Send: ");
fgets(send_buffer, 255, stdin);
socketIPv4_write(client, send_buffer);
char receive_buffer[1024];
socketIPv4_read(client, receive_buffer, 1024);
hexdump(receive_buffer, 1024);
socketIPv4_close(client);
return 0;
}