0

我用c编写了一个套接字程序。该程序会将数据从我的 android 手机发送到我的 PC。在这里,我需要将我的数据缓冲区大小增加到更大的大小,以便我可以发送大量数据。我使用 setsockopt() 系统调用来增加 tcp 缓冲区大小。但我的 android 不允许我将大小增加到 4096 字节以上。下面我粘贴了我的服务器端代码。需要帮忙

          int listenfd = 0;
             //Create a socket
                if((listenfd = socket(AF_INET, SOCK_STREAM, 0))==-1)
                {
                    printf("\n Could not create socket..");
                    return -1;
                }
         sock_buf_size=8192;
         setsockopt( listenfd, SOL_SOCKET, SO_SNDBUF,(char *)&sock_buf_size , sizeof(sock_buf_size));

         setsockopt( listenfd, SOL_SOCKET, SO_RCVBUF,(char *)&sock_buf_size , sizeof(sock_buf_size));

     serv_addr.sin_family = AF_INET;
        serv_addr.sin_addr.s_addr = INADDR_ANY;
        serv_addr.sin_port = htons(8888);
       // sock_buf_size = SOCKET_BUFF_SZ;


        //Binding the socket
        if(bind(listenfd, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) == -1 )
                printf("\nBind failed ");
        else    puts("\nBind done");




        //Listen to incoming connections
        listen(listenfd, 5);

        //Accept an incoming connection
        puts("\nWaiting for incoming connections...");
        c = sizeof(struct sockaddr_in);
        connfd = accept(listenfd, (struct sockaddr*)&client, &c);

 if((RcvdByteCnt = recv(connfd ,pSendBuff , BuffLength, 0)) != -1)
        {
            printf("\n Revived Byte->%d",RcvdByteCnt );

        }
4

0 回答 0