日期:2014-05-16  浏览次数:20717 次

大家看看我的程序,谢谢(80),先给20,解决后再给60
下面是小弟写的一个SOCKET程序,但是假如通过windows下的客户端连接他,并发送数据,它可以显示有客户端连接进来,但无法收到客户端发来的数据.怎么会事.谢谢大家.

#include   <sys/types.h>
#include   <sys/socket.h>
#include   <sys/time.h>
#include   <netinet/in.h>
#include   <stdio.h>
#include   <strings.h>
#include   <string.h>
#include   <errno.h>
#include   <arpa/inet.h>
#include   <stdlib.h>
#include   <unistd.h>
#include   <signal.h>
#include   <sys/wait.h>

#define   SA   struct   sockaddr
#define   MAXCLI   20
#define   MAXLINE     4096     /*   max   text   line   length   */
#define   LISTENQ   1024         /*   2nd   argument   to   listen()   */

void   sig_chld(int   signo)
{
        pid_t   pid;
        int   stat;
        while((pid   =   waitpid(-1,&stat,WNOHANG))> 0)
                printf( "chile   %d   terminated\n ",pid);
        return;
}

void   myWork(int   sockfd   )
{
        ssize_t   n=0;
        char   buf[1025];
        fd_set   rset;
        struct   timeval   timeout;
        timeout.tv_sec=2;
        timeout.tv_usec=0;
       
        bzero(&buf,sizeof(buf));
        printf( "i   am   in   myWork ");
    again:
                    while((n=read(sockfd,buf,1024))> 0)
                    {
                            printf( "[%d]   the   message   is:   %s ",getpid(),buf);
                            bzero(&buf,sizeof(buf));
                            //write(sockfd, "hello   client1\n ",sizeof( "hello   client1\n "));
                    }
                    if(n <0   &&   errno==EINTR)
                            goto   again;
                    else   if   (n <0)
                            printf( "str_echo:   read   error ");
    /*       FD_ZERO(&rset);
                    FD_SET(sockfd,&rset);
                    select(sockfd+1,&rset,NULL,NULL,&timeout);
    &nb