4 years, 8 months ago.

UDP sockets with http server

Hi, I have made a http webserver which is offering a web page, it is working fine :)

Now i want to integrate the udp socket with my server so that i can receive the udp packets from the udp servers.

Issue is when i tries to receives the udp message, it stucks the webpage mainly because it is waiting for the udp packet to receive so it not allows the rest of the code to execute to refresh the webpage. In order to refresh the page i need to send the udp packets. So in order to refresh the webpage udp socket needs to receive packets continuously. Here is a piece of code i am using to receive the udp packet

 UDPSocket server;
    // server.set_blocking(false,1000);
    Endpoint client;
    char buffer[512];
        printf("\nWait for packet...\n");
        int n = server.receiveFrom(client, buffer, sizeof(buffer));
        printf("Received packet from: %s\n", client.get_address());
       printf("n is %d \n",n);

My tcp server which is to server the webpage is developed by the following code :

void handleHTTPRequest(TCPSocketConnection *client)
    char * reqline[1];
    char * cgiTok;

    int i = 0;         
    char paramBuf[80];
    int bytesRecvd;
    char tempStr[80]; //PF was 26

    memset(requestBuffer,0,sizeof (requestBuffer));
    bytesRecvd = client->receive(requestBuffer, sizeof(requestBuffer));

    if(bytesRecvd > 0)
        // Received some data, check it and send data back
        reqline[0] = strstr(requestBuffer, "GET");
        if ( reqline[0] != NULL )
            if (strstr (requestBuffer, "HTTP/1.0") != NULL && strstr (requestBuffer, "HTTP/1.1") != NULL )
                client->send_all("HTTP/1.0 400 Bad Request\n", 25);
...// rest of code

Is there any solution for it, that I only receive the udp packet once it is ready to receive. I need solution like this :

if (socket is readable)
       int n = server.receiveFrom(client, buffer, sizeof(buffer));

thanks in advance

Comment on this question
Be the first to answer this question.

You need to log in to post a question