首页 > 解决方案 > 使用c语言在服务器套接字中连续读取字符串

问题描述

             x_hex=(char*)malloc(sizeof(char)*65);
             bzero(x_hex,65);
             check= read(newsockfd,x_hex,65);
             if ( check < 0)
             error("ERROR reading from socket");
             printf("Bytes recieved: %d\n", check);
             printf("x_hex is %s\n",x_hex);
             BN_hex2bn(&x, x_hex);
             free(x_hex);

             //second read

             y_hex=(char*)malloc(sizeof(char)*65);
             bzero(y_hex,65);
             check= read(newsockfd,y_hex,65);
             if ( check < 0)
                error("ERROR reading from socket");
             printf("Bytes recieved: %d\n", check);
             printf("y_hex  %s\n", y_hex);
             BN_hex2bn(&y, y_hex);
             free(y_hex);

输出-->

//x的输出应该是64,但是这里我只得到了1?

Bytes recieved: 1
comit1_x_hex from EV driver is 

Bytes recieved: 64
comit1_y_hex from EV driver is 
f0c8ff0cb9872942bc604523cb15243eafe12dc1bdd20339258f2d4eb0bcf1b9

标签: c

解决方案


推荐阅读