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 732337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:07:48+00:00 2026-05-14T07:07:48+00:00

all. I’m having a bit of weird problem with client server program. I have

  • 0

all. I’m having a bit of weird problem with client server program. I have two different kinds of clients trying to connect to one server, one is just more barebone than the other with less things to do. But other wise they are practically the same. While the barebone code can connect to server and server accepts it fine, the elaborate version of it can’t. The client says it’s connected, sends messages (via both send() and sendto()) and gets number of bytes sent back. But the server doesn’t recognize it. I’m not really sure why, esp upon comparing both versions of clients, they are really the same thing (at least until connect() is called), elaborate version has bind() whereas barebone version doesn’t. Can anybody see a problem as to why these very similar codes don’t work similar 😛

    if (argc == 3)
{
    host = argv[1];         // server address
    info.c_name = argv[2];
}
else
{
    printf("plz read the manual, kthxbai\n");
    exit(1);
}

hp = gethostbyname(host);
if (!hp)
    exit(1);
printf("host found\n");

// setting up address and port structure information
bzero((char * ) &server_address, sizeof(server_address));
server_address.sin_family = AF_INET;
server_address.sin_addr.s_addr = htonl(INADDR_ANY);
server_address.sin_port = htons(SERVER_PORT);


// opening up socket
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd < 0)
    exit(1);
else
    printf("socket is opened: %i \n", sockfd);
info.sock_fd = sockfd;


// binding socket to a port: not in barebone version
rv = bind(sockfd, (struct sockaddr *) &server_address, sizeof(server_address));
if (rv < 0)
{
    printf("MAIN: ERROR bind() %s\n", strerror(errno));
    exit(1);
}
else
    printf("socket is bound\n");

// connecting
rv = connect(sockfd, (struct sockaddr *) &server_address, sizeof(server_address));
printf("rv = %i\n", rv);
if (rv < 0)
{
    printf("MAIN: ERROR connect() %i:  %s\n", errno, strerror(errno));
    exit(1);
}
else
    printf("connected\n");

I’m not even sure where the problem is, whether it’s the elaborate version of client or it’s just the server? Thanks for any enlightenment.

  • 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-05-14T07:07:48+00:00Added an answer on May 14, 2026 at 7:07 am

    If the code is really what you’re using, your client is (magically!) connecting to itself, due to TCP’s somewhat obscure Simultaneous connect support.

    The problem here is that you aren’t using the return for gethostbyname at all.
    You also shouldn’t bind the server port if it might be running on the local machine.

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

Sidebar

Related Questions

All -- I have these two methods in one of my classes: public static
all. We're trying to get some intersect collisions working, but the problem experience is
All, Say I have the following bit of code: select: function(start, end, allDay) {
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
All, I currently have two projects that are under SourceSafe that I am unable
All, I have some script tags that are not working in Wordpress. If I
All, I am trying to create a table to receive user inputs (UGC). This
All, I have the following code: $fetch = mysql_query(SELECT * FROM calendar_events where event_status='booked'
All the examples of use and tutorials I have found on beginBackgroundTaskWithExpirationHandler: show how
All, I have a form with a MultiValueField that almost works. It uses a

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.