[code:1]
void showerr(const char *err)
{
perror(err); exit(1);
}
int main(int arg,char **argv)
{
int sck,flag,length,rc;
struct sockaddr_in saddri,caddri;
char rbuf[512],sbuf[512];
time_t td;
struct tm tm;
memset(&tm,sizeof(tm),0);
length=sizeof saddri;
saddri.sin_port=htons(9099);
saddri.sin_family=AF_INET;
saddri.sin_addr.s_addr=inet_addr("172.19.60.215");
sck=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
if(sck==-1)
showerr("socket()");
flag=bind(sck,(struct sockaddr*)&saddri,length);
if(flag==-1)
showerr("bind()");
while(1)
{
length=sizeof caddri;
rc=recvfrom(sck,rbuf,sizeof(rbuf),0,(struct sockaddr*)&caddri,&length);
if(rc==-1)
showerr("revcfrom()");
rbuf[rc]=0;
if(!strcasecmp(rbuf,"QUIT"))
break;
time(&td);
tm=*localtime(&td);
strftime(sbuf,sizeof(sbuf),rbuf,&tm);
rc=sendto(sck,sbuf,sizeof(sbuf),0,(struct sockaddr*)&caddri,length);
if(rc==-1)
showerr("sendto()");
}
close(sck);
return 0;
}[/code:1]
运行时出错:
revcfrom(): Transport endpoint is not connected
跟着就退出了。但编译时没问题啊!
同时客户端连接连接时提示:断开的管
怎么回事呢?
谢谢!! |