当前位置: 技术问答>linux和unix
帮我看下UNIX下用SOCKET实现文件传输哪出错了
来源: 互联网 发布时间:2016-04-02
本文导语: 服务器的 #include #include #include #include #include #include #include main() { char c,buf[1024],file[30]; int fromlen,source; register int k,s,ns; struct sockaddr_in sin; struct hostent *hp; ...
服务器的
#include
#include
#include
#include
#include
#include
#include
main()
{
char c,buf[1024],file[30];
int fromlen,source;
register int k,s,ns;
struct sockaddr_in sin;
struct hostent *hp;
system(″clear″);
printf(″n″);
printf(″nntt输入要传输的文件名:″);
scanf(″%s″,file);
if ((source=open(file,O_RDONLY))h_length);
if(bind(s,&sin,sizeof(sin))0)
write(target,buf,k);
if(k==-1) {
if(errno==EINTR||errno==EAGAIN || errno == EWOULDBLOCK)
continue;
else
break; //error happened
}
}
#include
#include
#include
#include
#include
#include
#include
main()
{
char c,buf[1024],file[30];
int fromlen,source;
register int k,s,ns;
struct sockaddr_in sin;
struct hostent *hp;
system(″clear″);
printf(″n″);
printf(″nntt输入要传输的文件名:″);
scanf(″%s″,file);
if ((source=open(file,O_RDONLY))h_length);
if(bind(s,&sin,sizeof(sin))0)
write(target,buf,k);
if(k==-1) {
if(errno==EINTR||errno==EAGAIN || errno == EWOULDBLOCK)
continue;
else
break; //error happened
}
}