commfun.cpp

来自「使用于2410终端上的一个播放类似ppt文件的程序,涉及Tcp/IP通信、局域网」· C++ 代码 · 共 38 行

CPP
38
字号
#include <netinet/in.h>#include <arpa/inet.h>#include <stdlib.h>#include <stdio.h>#include <string.h>#include <syslog.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <unistd.h>#include <termios.h>#include <sys/socket.h>#include <pthread.h>#include "mytypes.h"int savefile(char* filename,char* pdata,int ilen){	FILE* file=fopen(filename,"w+b");	fwrite(pdata,1,ilen,file);	fclose(file);}int recvn(int sock,char* pbuff,int ilen){	//assert(sock>0&&pbuff&&ilen>0);	int irevlen=0,i;	char * ptemp=pbuff;	while(irevlen<ilen)	{		if ((i=recv(sock,ptemp,1024,0))>0)		{			irevlen+=i;			ptemp+=i;		}			else return -1;	}	return 1;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?