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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:06:13+00:00 2026-05-13T21:06:13+00:00

Sorry for a very generic sounding question. let’s say #include <sys/socket.h> #include <sys/types.h> #include

  • 0

Sorry for a very generic sounding question.

let’s say

#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>


#define SERVER_ADDRESS  "123.456.789.012"
#define CLIENT_ADDRESS  "123.456.789.013"

#define SERVER_TCP_PORT "1234"
#define CLIENT_TCP_PORT "1235"


int main()
{
    printf("o halo thar");


    int sockfd, new_sockfd, msg_len;
    void * got_msg = "got ur msg!";
    void * message;
    struct sockaddr_in server_address, client_address;


    if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0 )
        exit(1);
    printf("socket is opened");

    bzero((char * ) &server_address, sizeof(server_address)); 
    server_address.sin_family = AF_INET;
    server_address.sin_addr.s_addr = htonl(SERVER_ADDRESS);
    server_address.sin_port = htons(SERVER_TCP_PORT);


    if (bind(sockfd, (struct sockaddr *) &server_address, sizeof(server_address)) < 0)
        exit(1);
    printf("socket is bound");

    listen(sockfd,11);
    printf("listening");

    if (accept(sockfd, (struct sockaddr *) &client_address, sizeof(client_address)) < 0) // THE BAD LINE 
        exit(1);
    printf("accepted"); 

    int i;
    for( i = 0; i < 11; i++)
    {
        msg_len = recv(sockfd, (void *) message, 10000, 0);
        if (msg_len < 1)
            exit(1);
        printf("receiving msg");

        if (send(sockfd, (void *) got_msg, 10000, 0) < 0);
            exit(1);
        printf("sending msg");
    }

    close(sockfd);

}

it should print abc if everything runs correctly. of course, my code doesn’t. but i have localized the problem to this certain line of code which i’m calling somecode(). when i comment out somecode(), the program prints out ab (not c). however when not commented out, it prints nothing. so what kind of problem am i running into that affects previous statements? sorry for the vagueness. i’m just wondering how seeing somecode() is compiled fine, but when running, it influences executions of code that should be done before it reaches somecode()? Thanks guys.

EDIT:somecode() being

   if (accept(sockfd, (struct sockaddr *) &client_address, sizeof(client_address)) < 0)
      exit(1);

EDIT2:
sorry for being too vague. i even forgot to describe what happens to the program. it doesn’t print anything out and i have to ctrl+c in order to get out of it.

  • 1 1 Answer
  • 2 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-13T21:06:13+00:00Added an answer on May 13, 2026 at 9:06 pm

    What happens if you fflush(STDOUT) after each call to printf? Maybe your program is dying before printing all buffered output.

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

Sidebar

Related Questions

This is going to be a very generic question and I'm sorry. But lets
First of all, I want to say sorry for this very big question, but
I am very sorry to ask such a basic question but I am new
This is a question corresponds to my uni assignment so I am very sorry
Sorry if this question is very easy, but I can't find the answer anywhere.
Sorry this is not a very well defined question, I am thinking about an
I am very sorry if my question doesn't make sense as this is my
I'm very sorry about this being a very cliché question, but I really need
Sorry for the very basic question. What does the & operator do in this
Sorry for the very involved question, but this is something I've been researching for

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.