当前位置: 技术问答>linux和unix
大家都来讨论一下socket丢数据的问题!
来源: 互联网 发布时间:2015-04-04
本文导语: 我的代码如下: bzero(&pin,sizeof(pin)); pin.sin_family=AF_INET; pin.sin_addr.s_addr=htonl(INADDR_ANY); pin.sin_addr.s_addr=((struct in_addr *)(server_host_name->h_addr))-s_addr; pin.sin_port=htons(port); if ((socketfd=socket(AF_INET,SOCK_STREAM,0))==-1){ perror("Error ope...
我的代码如下:
bzero(&pin,sizeof(pin));
pin.sin_family=AF_INET;
pin.sin_addr.s_addr=htonl(INADDR_ANY);
pin.sin_addr.s_addr=((struct in_addr *)(server_host_name->h_addr))-s_addr;
pin.sin_port=htons(port);
if ((socketfd=socket(AF_INET,SOCK_STREAM,0))==-1){
perror("Error opening socketn");
exit(1);
}
if (connect(socketfd,(void *)&pin,sizeof(pin))==-1){
perror("Error connecting to socketn");
exit(1);
}
sleep(1);
for(;;){
revcount=recv(socketfd,buf2,60,0);
if (revcount
bzero(&pin,sizeof(pin));
pin.sin_family=AF_INET;
pin.sin_addr.s_addr=htonl(INADDR_ANY);
pin.sin_addr.s_addr=((struct in_addr *)(server_host_name->h_addr))-s_addr;
pin.sin_port=htons(port);
if ((socketfd=socket(AF_INET,SOCK_STREAM,0))==-1){
perror("Error opening socketn");
exit(1);
}
if (connect(socketfd,(void *)&pin,sizeof(pin))==-1){
perror("Error connecting to socketn");
exit(1);
}
sleep(1);
for(;;){
revcount=recv(socketfd,buf2,60,0);
if (revcount