如何设置android tcp缓冲区大小

时间:2013-10-24 10:25:00

标签: android sockets tcp android-ndk android-networking

我在c中编写了一个套接字程序。该程序将从我的Android手机发送数据到我的电脑。这里我需要的是,我想将数据缓冲区大小增加到更大的数据,以便我可以发送大量数据。我使用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 );

        }

0 个答案:

没有答案