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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:10:09+00:00 2026-06-03T22:10:09+00:00

I have to write a simple chat in C. One program is a server

  • 0

I have to write a simple chat in C. One program is a server to which clients connect and it manages the messages they send. Client is another program and here I’ve got a problem. I’d like to be able to receive messages from other clients (through the server) and print them on the console output. Yet at the same time I’d like to be able to write my own message and send it to the server (and therefore to other clients).
Problem is, when I write some message, meanwhile receive one from the server, the whole input is messed up. I’d like to somehow separate the message-output area and message-input area. Is there any good way to do that? This is my fork in the client program (still a draft):

int pid = fork();
if(pid==0){
    do{
        scanf("%s", msg);
        printf("sending the message to the server\n");
    } while(strcmp(msg, "exit"));
    kill(getppid(), SIGKILL);
    printf("kill the child\n");
} else {
    while(1){
        printf("receiving a new message\n");
        sleep(1);
    }
}

EDIT:
Ok, I’ve made a simple ncurses application, but there’s one more issue. How could I write to the same window in ncurses when I have two processes (after fork())? They seem to have their separate windows and either I can provide input or read output from the server, but not both on one screen. Any proposals? I didn’t want to make IPC between them, only between clients and the server.

EDIT2:
I finally gave up the idea of ncurses due to the approaching deadline. If the program was multithreaded (not multi-processed), then it would work perfectly, but with fork it all became a mess. Anyway, I made my final project in ncurses, so still a useful suggestion 🙂

  • 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-03T22:10:10+00:00Added an answer on June 3, 2026 at 10:10 pm

    You don’t mention whether you’re on Windows or Linux…this answers assumes Linux, for the most part.

    A typical solution is to use something like ncurses to separate the screen into two “windows”, then display messages received from other clients in one window and your input in another window. Curses is a library for taking advantage of terminal control codes for cursor positioning and so forth to provide a simple console-based GUI.

    If you’ve ever used an irc client, you’ve already experienced something like what I’m describing.

    There’s a ncurses programming HOWTO, which might be a good place to start.

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

Sidebar

Related Questions

I have created a simple chat server that is driven by client polling. Clients
I have been working on a (relatively) simple tcp client/server chat program for my
I am trying to write a simple chat server which sends commands from ajax
I'm trying to write a simple client/server chat application in 2 languages - Java
I am new to java NIO. I have to write a simple server client
I have to write a program that sniffs network packets (part1-the simple part). And
I'm looking to write a simple proxy server in .NET. Does anyone have any
I'm trying to write a simple stock check program, and I have a Table
Hello every one I have wrote a simple code in html5 in which I
I'm building a simple chat server in java , where users can have private

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.