資源簡介
UNIX網絡編程中所有源代碼和編譯環境搭建
代碼片段和文件信息
#include “unp.h“
int
main(int?argc?char?**argv)
{
int sockfd?n?npend;
char recvline[MAXLINE?+?1];
socklen_t len;
struct?sockaddr_storage ss;
if?(argc?!=?3)
err_quit(“usage:?a.out??“);
sockfd?=?Tcp_connect(argv[1]?argv[2]);
len?=?sizeof(ss);
Getpeername(sockfd?(SA?*)&ss?&len);
printf(“connected?to?%s\n“?Sock_ntop_host((SA?*)&ss?len));
for?(?;?;?)?{
if?(?(n?=?Recv(sockfd?recvline?MAXLINE?MSG_PEEK))?==?0)
break; /*?server?closed?connection?*/
Ioctl(sockfd?FIONREAD?&npend); /*?check?FIONREAD?support?*/
printf(“%d?bytes?from?PEEK?%d?bytes?pending\n“?n?npend);
n?=?Read(sockfd?recvline?MAXLINE);
recvline[n]?=?0; /*?null?terminate?*/
Fputs(recvline?stdout);
}
exit(0);
}
- 上一篇:FFT_XILINX實現
- 下一篇:路徑文件夾更改器
評論
共有 條評論