#include <stdio.h>#include <winsock.h>#pragma comment(lib,"Ws2_32")#define MAXSIZE 100main(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;}
2 回答
FFIVE
TA贡献1797条经验 获得超6个赞
也已经提示的很清楚了...
你先看一个函数原形吧
int recv(
SOCKET s,
char FAR *buf,
int len,
int flags
);
Parameters
s
[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.
- 2 回答
- 0 关注
- 174 浏览
添加回答
举报
0/150
提交
取消