以下内容是关于socket编程的“recv”函数,但是通不过编译,为什么?

#include <stdio.h>
#include <winsock.h>
#pragma comment(lib,"Ws2_32")
#define MAXSIZE 100
main(int argc,char *argv[])
{
int bytenum=0,
char buf[MAXSIZE];

SOCKET socket_fd;
struct sockaddr_in their_addr;
WSADATA ws;
WSAStartup(MAKEWORD(2,2),&ws);
socket_fd=socket(AF_INET,SOCK_STREAM,0);
their_addr.sin_family=AF_INET;
their_addr.sin_port=htons(830);
their_addr.sin_addr.s_addr=inet_addr(argv[1]);
bind(socket_fd,(struct sockaddr *)&their_addr,sizeof(struct sockaddr));
connect(socket_fd,(struct sockaddr *)&their_addr,sizeof(struct sockaddr));
printf("connecting.....");
bytenum=recv(socket_fd,buf,MAXSIZE,0);
buf[bytenum]='\0';
printf("receive %s",buf);
closesocket(socket_fd);
return 0;
}

慕的地10843
浏览 175回答 2
2回答

FFIVE

也已经提示的很清楚了...你先看一个函数原形吧int recv(SOCKET s,char FAR *buf,int len,int flags);Parameterss[in] Descriptor identifying a connected socket.buf[out] Buffer for the incoming data.len[in] Length of buf.flags[in] Flag specifying the way in which the call is made.

慕村9548890

第一个分号该改为逗号
打开App,查看更多内容
随时随地看视频慕课网APP