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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:59:59+00:00 2026-05-25T18:59:59+00:00

This is my first time ever using sockets, and I am having trouble accepting

  • 0

This is my first time ever using sockets, and I am having trouble accepting connections on the server side. My server is only designed to accept one connection at a time. Once a connection is received, the current date and time are written to the socket, and then the client prints out the date and time it received from the server. My server has the following code:

cout << "Server: Waiting for connections." << endl;
client_length = sizeof(client_address);
connection_fd = accept(listen_fd, (struct sockaddr*)&client_address, (socklen_t*)&client_length);
cout << "Server: Client connected" << endl;

When I run my server, I get the following output:

./server&
Server: Waiting for connections.

Then when I run my client, I get the following output:

./client 127.0.0.1
Client: Connecting to: 127.0.0.1
Client: Connected to server.
Sun Sep 25 13:20:07 2011

The client seems to print out the correct data, but the server never prints out that a client connected. Something is wrong here. Another symptom is when I try to write to the pipe (client writes, server reads), the client gets a broken pipe error. Is there something I am missing? If there is any code you would like to see, please ask.

Edit: Here is the server running under strace. Nothing seems to happen after accept is printed out. Weird?

write(2, "Server: Socket created.", 23Server: Socket created.) = 23
write(2, "\n", 1
)                       = 1
bind(3, {sa_family=AF_INET, sin_port=htons(4007), sin_addr=inet_addr("0.0.0.0")}, 16) = -1 EADDRINUSE (Address already in use)
write(2, "Server: Address and port bound t"..., 41Server: Address and port bound to socket.) = 41
write(2, "\n", 1
)                       = 1
listen(3, 100)                          = 0
write(2, "Server: Socket is now a listenin"..., 41Server: Socket is now a listening socket.) = 41
write(2, "\n", 1
)                       = 1
write(2, "Server: Waiting for connections.", 32Server: Waiting for connections.) = 32
write(2, "\n", 1
)                       = 1
accept(3,  

Thanks.

  • 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-25T19:00:00+00:00Added an answer on May 25, 2026 at 7:00 pm

    This shouldn’t happen.

    It’s even hard to imagine a broken scenario, like you have two instances of the server running, and the other one is accepting the connections, but then the new instance shouldn’t be able to use the same port number again, so you probably doesn’t verify return values of system calls, but then accept should fail, and you should see a false client connected message.. so, what the heck are you doing?

    Update: yepp… -1 EADDRINUSE (Address already in use)

    Another instance is running, or something else that uses that port number. Check with netstat. And for god’s sake check the return values of those calls.

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

Sidebar

Related Questions

I'm am super new at this, and this is my first time ever using
This is the first time ever I'm using AJAX, and I want to do
I have recently started learning F#, and this is the first time I've ever
This is my first time using joomla. I don't know if I'm using the
I'm using Ajax via jQuery for the first time ever. I have an html
http://localhost:3000/genre I'm using Instant Rails, I'm introducing scaffolding for the first time ever. So
this is my first time using Eclipse, and my first time programming in a
This is my first time attempting to call an ASP.NET page method from jQuery.
This is my first time with Web services. I have to develop web services
This is a really basic question but this is the first time I've used

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.