我正在尝试使用 C 套接字编程将文件从客户端发送到服务器。但是在服务器端,我无法接收从客户端发送的文件。我附上下面的代码。
服务器:
/* Create a connection queue and wait for clients. */
listen(server_sockfd, 5);
while(1) {
char ch;
printf("server waiting\n");
/* Accept a connection. */
client_len = sizeof(client_address);
client_sockfd = accept(server_sockfd,(struct sockaddr*)&client_address,cli);
if(client_sockfd > 0)
printf("client is connected\n");
/* We can now read/write to client on client_sockfd. */
char *fh;
recv(client_sockfd,fh,1024+1,0);
printf("server recieved %s",fh);
/* read(client_sockfd, &ch, 1);
ch++;
write(client_sockfd, &ch, 1); */
return close(client_sockfd);
}
}