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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:24:31+00:00 2026-06-01T20:24:31+00:00

This question uses the code for server.c and client.c found here. I want a

  • 0

This question uses the code for server.c and client.c found here.

I want a server to send a message to a client when a client has connected.

As you can see from the article, what the code does is have the server wait for a client to connect, listens to it, and then prints out the message the client gives it, and also an alert to the client.

Here’s what I’ve tried to do to solve my problem (everything else is exactly the same). server:

 ...
 newsockfd = accept(sockfd, 
             (struct sockaddr *) &cli_addr, 
             &clilen);
 if (newsockfd < 0) 
      error("ERROR on accept");
 else
 {
      write(newsockfd,"I got your message",18);
 }
 ....

And on client side, (again, everything else the same):

...
if (connect(sockfd,(struct sockaddr *) &serv_addr,sizeof(serv_addr)) < 0) 
    error("ERROR connecting");
bzero(buffer,256);
read(sockfd,buffer,255);
...

It seems I should be able to do this with just these couple lines. But the behavior of the code remains exactly the same as the original! What’s going on?

  • 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-01T20:24:32+00:00Added an answer on June 1, 2026 at 8:24 pm

    For server, insert

     bzero(buffer,256);
     n = write(newsockfd,"Client connected", 16);
     if (n < 0) error("ERROR writing to socket");
    

    after accept().

    For client, insert

    bzero(buffer,256);
    n = read(sockfd,buffer,255);
    if (n < 0) 
         error("ERROR writing to socket");
    printf("%s\n", buffer);
    

    after connect().

    Is this what you want? I think you should be able to infer from the rest of the existing code.

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

Sidebar

Related Questions

Looking in this StackOverflow question it uses the following to send emails: System.Net.Mail.SmtpClient Is
This question already has an answer here: What are Extension Methods? 5 answers Usage
This relates to my other question on accessing a REST service that uses forms
I'm writing test code to test a client-server application. The application under test consists
I implemented a Client and Server model that uses Socket with thread When I
Based on examples here , the simple socket server client will terminate when .bye
This is a generic C++ design question. I'm writing an application that uses a
I am working on a client-server application that uses boost::serialization library for it's serialization
My company has developed a .NET web service and a client dll that uses
This Question is similar but the accepted answer solves it server side, I'm interested

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.