问题现象:服务器端accept使用下述方式,read读取字符串乱码
int Server::ServerAcceptRequest()
{
clientSockfd = accept(serverSockfd, (struct sockaddr *)clientAddr, (socklen_t *)sizeof(struct sockaddr_in));
return clientSockfd;
}
解决方式:
int Server::ServerAcceptRequest()
{
static int len = sizeof(struct sockaddr_in);
clientSockfd = accept(serverSockfd, (struct sockaddr *)clientAddr, (socklen_t *)&len);
return clientSockfd;
}