socket实现服务器方程序:求解!急急急!!!
服务器方程序: //File Name:streams.c
#include<winsock.h>
#include<stdio.h>
#define TRUE1
main()
{
int sock.,length ;
struct sockaddr_in server;
struct sockaddr tcpaddr;
int msgsock;
char buf[1024];
int rval,len;
sock=socket(AF_INET,SOCK_STREAM,0);
if(sock<0){
perror(“opening stream socket”);
exit(1);
}
server.sin_family=AF_INET;
server.sin_port=INADDR_ANY;
if(bind(sock,(struct sockaddr*)&server,sizeof(server))<0{
perror(“binding stream socket”);
exit(1);
}
length=sizeof(server);
if(getsockname(sock,,(struct sockaddr*)&server,&length)<0{
perror(“getting socket name”);
exit(1);
}
printf(“socket port #%d\n”,ntohs(sener.sin_port)),
listen(sock,5);
len=sizeof(struct sockaddr);
do{
msgsock=accept(sock,(struct sockaddr*)&tcpaddr,(int*)&len;
if(msgsock==-1)
perror(“accept”);
else do {
mense(buf,0,sizeof(buf));
if(rval=recv(msgsock,buf,1024))<0)
perror(“reading stream message”);
if(rval==0)
prinft(“ending connection\n”);
else
printf(-->%s\n”,buf);
}while (rval!=0);
closesocket(msgsock);
}whie(TURE);
exit(0);
}
求解每句话的意思,还有if(sock<0) ,if(bind(sock,(structsockaddr*)&server,sizeof(server))<0{
if(rval=recv(msgsock,buf,1024))<0
//为什么都要小于零,小于别的不可以么?if(msgsock==-1)为什么要等于-1?