Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8187939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:44:11+00:00 2026-06-07T02:44:11+00:00

I’m writing a Minecraft Classic Server in C using TCP sockets in Winsock and

  • 0

I’m writing a Minecraft Classic Server in C using TCP sockets in Winsock and I’m writing the function to perform a ‘heartbeat’, just an HTTP request which should return a URL to me – no headers or HTML at all.

It sends the data to Minecraft.net (at least it says it does) but it just sits there for a few minutes after that and eventually tells me that it got no data from minecraft.net, ie it reads “HeartBeat: Recieved no data from minecraft.net”

I have the following code so far (excluding WSAStartup etc.):

void HeartBeat()
{
    unsigned int clSock;
    struct hostent *host;
    struct sockaddr_in server_addr;
    char buffer[128] = "";
    char request[256] = "GET /"; //(I will not show the rest of the request...)
    if((clSock = socket(AF_INET, SOCK_STREAM, 0)) < 0)
    {
            printf("HeartBeat: Error creating socket\n");
            return;
    } else {
            printf("HeartBeat: Success in creating socket\n");
    }
    printf("HeartBeat: Resolving hostname 'www.minecraft.net'... ");
    if((host = gethostbyname("www.minecraft.net")) == NULL)
    {
        printf("failed\n");
        return;
    } else {
        printf("success!\n");
    }
    server_addr.sin_family = AF_INET;
    server_addr.sin_port = htons(80);
    server_addr.sin_addr.s_addr = *((unsigned long*)host->h_addr);
    if (connect(clSock, (SOCKADDR*) &server_addr, sizeof(server_addr)) == SOCKET_ERROR)
    {
        printf("HeartBeat: Error conneting to www.minecraft.net\n");
        return;
    } else {
        printf("HeartBeat: Connected to www.minecraft.net\n");
    }
    if (send(clSock, request, sizeof(request), 0) < 0)
    {
        printf("HeartBeat: Sending data failed.\n");
        closesocket(clSock);
        return;
    } else {
        printf("HeartBeat: Success in sending data.\n");
    }
    if ((recv(clSock, buffer, sizeof(buffer), 0)) == 0)
    {
        printf("HeartBeat: Received no data from www.minecraft.net\n");
        closesocket(clSock);
        return;
    } else {
        printf("HeartBeat: Yay, success! Url is '%s'", buffer);
        closesocket(clSock);
        return;
    }
}

Could someone please point out where I’ve gone wrong? Thanks a million.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T02:44:13+00:00Added an answer on June 7, 2026 at 2:44 am

    You’re not sending an HTTP request.

    A (minimal) HTTP request would have to be at least the string:

    char request[256] ="GET / HTTP/1.0\r\n\r\n";
    

    Or in the case of HTTP 0.9:

    char request[256] ="GET /\r\n\r\n";
    

    You must send just that string, not the whole request buffer containing a lot of 0 bytes, so do:

     send(clSock, request, strlen(request), 0)
    

    You are doing just 1 recv() call, that might not read the entire response. You’re supposed to read until the connection closes (until recv() returns 0). Or to really follow the HTTP protocol, you need to parse the response, look for a Content-Length header. Read all the headers, then read the number of bytes in the body (if any). To really cope with all the minute details of HTTP, you really need a HTTP library though.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.