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

  • Home
  • SEARCH
  • 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 77373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T20:49:12+00:00 2026-05-10T20:49:12+00:00

I’m trying to make a TCP Client program in C where the client will

  • 0

I’m trying to make a TCP Client program in C where the client will start up, connect to a server. Then it will send a little information and then just listen to what it receives and react accordingly.

The part that I’m having trouble with is the continuous listening. Here is what I have

...  while (1) {    numbytes = recv(sockfd, buf, MAXDATASIZE-1, 0);    buf[numbytes] = '\0';    printf('Received: %s\n', buf);    // more code to react goes here }  ... 

Upon connecting to the server, after sending two lines of data, the server should receive a good bit of information, but when I run this, it prints:

Received:

And then continues to just sit there until i force it to close.

** EDIT ** when i do what Jonathan told me to do, I get the following:

Count: -1, Error: 111, Received:

So that means its erroring, but what do i do about it?

  • 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. 2026-05-10T20:49:13+00:00Added an answer on May 10, 2026 at 8:49 pm

    Print out the number of bytes received – it is likely to be zero, but confirm that.

    It would be worth checking that you aren’t getting an error – and therefore underflowing your buffer.

    [Note: from here onwards is the work of Pax – thank you, and I’ve converted it to Community Wiki so I don’t get rep points undeservedly.]

    The following code will do this. Try it and report back on the results, please.

    while (1) {     numbytes = recv(sockfd, buf, MAXDATASIZE-1, 0);     buf[numbytes] = '\0';     printf('Count: %d, Error: %d, Received: %s\n', numbytes, errno, buf);     // more code to react goes here } 

    After question edit:

    Error number 111 is ECONNREFUSED – this is not a usual error code for recv(), but is more suited to the open-type call (open(), connect(), etc).

    In any case, ECONNREFUSED is a problem at the server end, not the client – the server has purposefully refused to accept your incoming connection, so you will need to investigate that end of the link.

    In order to test this, change your code so that it’s connecting to http://www.microsoft.com on port 80, then send a couple of lines of any old rubbish. You should get back an error from their web server indicating a malformed HTTP request. This will prove there’s no problem on your client end.

    This is what I get back when I telnet www.microsoft.com 80 and type in hello followed by ENTER twice:

    HTTP/1.1 400 Bad Request Content-Type: text/html; charset=us-ascii Server: Microsoft-HTTPAPI/2.0 Date: Thu, 27 Nov 2008 01:45:09 GMT Connection: close Content-Length: 326  <!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01//EN''http://www.w3.org/TR/html4/strict.dtd'> <HTML><HEAD><TITLE>Bad Request</TITLE> <META HTTP-EQUIV='Content-Type' Content='text/html; charset=us-ascii'></HEAD> <BODY><h2>Bad Request - Invalid Verb</h2> <hr><p>HTTP Error 400. The request verb is invalid.</p> </BODY></HTML> 

    You should see something similar.

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

Sidebar

Ask A Question

Stats

  • Questions 93k
  • Answers 93k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Umm, .NET Reflector? Edit: To find detailed information on the… May 11, 2026 at 6:33 pm
  • Editorial Team
    Editorial Team added an answer Where has the common UI come from and how difficult… May 11, 2026 at 6:33 pm
  • Editorial Team
    Editorial Team added an answer Try setting EnableViewStateMac to falseon the page to see if… May 11, 2026 at 6:33 pm

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.