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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T02:12:34+00:00 2026-05-21T02:12:34+00:00

I am trying to have 2 way communication running between C sockets. For having

  • 0

I am trying to have 2 way communication running between C sockets. For having the sockets set up, I was following the instructions on this link (http://www.linuxhowtos.org/C_C++/socket.htm) and everything worked fine. Sending messages from the client to the server worked perfectly.

However, I would also like the ability of the server to send response messages back to the client. How is this accomplished? If I set up a client and server connection at both ends, one of them cannot bind.

edit more code. Currently, I’ve used this style of sockets and put them into c++ code, just because that’s my familiarity. Ignore the object oriented-ness.

//main call
if (server)
    {
        Connection recv(true, "servername");
        recv.GetMsg();
        recv.SendMsg("test", 4);
    }
    else // client
    {
        Connection snd(false, "servername");
        snd.GetMsg();
        snd.SendMsg("this is a test", 14);
    }

And inside the Connection class,

void SendMsg(char *msg, int msg_length)
{
        send(some_socket, msg, msg_length, 0);
};

void GetMsg()
{
        recvd = recv(opponent_socket, buffer, sizeof(buffer), 0);
        buffer[recvd] = '\0';
        cout << "Printing msg: " << buffer << endl;
};

Connection::Connection(bool isserver, char *servername)
{
    is_server = isserver;
    server = servername;
    opponent_socket = 0;
    some_socket = socket(PF_INET, SOCK_STREAM, 0);

    if (some_socket < 0)
    {
        cout << "Connection failed.\n" << endl;
        exit(-1);
    }

    if (is_server)
    {
        AddrSetupServer(); // standard calls here.  Pretty well what's shown in link provided
        BindServer();
        ListenServer();
        WaitConnectionServer();
    }
    else
    {
        AddrSetupClient();
        ConnectClient();
    }
};
  • 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-21T02:12:34+00:00Added an answer on May 21, 2026 at 2:12 am

    Once you have a connection, it is bidirectional; simply send your response over the socket.

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

Sidebar

Related Questions

I have been trying to find a really fast way to parse yyyy-mm-dd [hh:mm:ss]
I have been trying to work my way through Project Euler, and have noticed
I am trying to find a way to have a SELECT statement return the
I'm trying to figure out if there is any way to have a .NET
I have a ListView control, and I'm trying to figure out the easiest/best way
I'm trying to have my Struts2 app redirect to a generated URL. In this
I am trying to have a logout page where is displays a messages and
I'm trying to have a new layer appear above existing content on my site
I am trying to have one one layer, and center images within. I.E., if
I am trying to have a tooltip on multiple lines. how do i do

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.