通过套接字发送avro(avro c)编码数据我试图在将avro编码数据转换为字节数组(使用memcpy)之后通过套接字发送avro编码数据。我所做的如下所示
/客户端:client.c /
avro_datum_t t_msg = avro_record(temp_schema);
avro_record_set(t_msg, "TIME", time_datum) // encoded like this
...
...
unsigned char *temp=(unsigned char *) malloc(sizeof(t_msg));
memcpy(temp,&t_msg,sizeof(t_msg));//converting to byte array
sendto(sock, &temp, strlen(temp), 0, (struct sockaddr *)&server_addr, sizeof(struct sockaddr));//send to socket
/服务器端:server.c /
avro_datum_t time_datum;
..
..
unsigned char *recv_data=(unsigned char *) malloc(sizeof(t_msg));
avro_datum_t t_msg;
bytes_read = recvfrom(sock,recv_data,1024,0,(struct sockaddr *)&client_addr, &addr_len);
memcpy(bgpmsg1,recv_data,sizeof(recv_data));
if (avro_record_get(t_msg, "TIME", &time_datum) == 0) {
printf("\nHi...0\n");
avro_string_get(time_datum, &p);
fprintf(stdout, "TIME: %s ", p)
}
//trying to decode and print message like this
但它没有得到任何东西......当我尝试在 clent.c 本身中解码和打印时,它正在被打印出来。但是通过套接字发送后它无法检索..