Help with ncurses and fork()

This is a discussion on Help with ncurses and fork() within the C Programming forums, part of the General Programming Boards category; I'm working on a chat app, I'm using ncurses, I create 3 screens with ncurses, an input screen to type ...

  1. #1
    Registered User
    Join Date
    Sep 2012
    Posts
    28

    Help with ncurses and fork()

    I'm working on a chat app, I'm using ncurses, I create 3 screens with ncurses, an input screen to type in the input, a message screen to display the messages, and a screen to list all the logged on users. I needed the input to be constantly active, and waiting for input, while having the message and user screens constantly being updated, so I used fork, the parent process handles user input, and the child process loops through constantly checking for new logged in users and new messages. Now everything works great, with one exception, when I have it post from the parent process I have it print it to the message screen as 'You: message'.

    Now what's happening is the text that's printed from the parent process (the text the user types in) overlapps the text printed from the child process, my best guess is when it forks it creates two virtual terminals that each have their own set of text.

    So far, I've tried making a pipe, and having the parent pipe the text to the child, but to no avail, if anyone has any ideas how I could fix this issue I'd greatly apprecieate it.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,451
    You could do away with all the forked processes, and just have a single process doing everything.

    You can use ncurses to read the console without blocking.

    For all the network sockets, use select() to watch for changes. You can use the timeout feature of select to stop it from blocking, if none of your connections have activity.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Sep 2012
    Posts
    28
    I know about changing sockets to non-blocking mode, but I don't know about that in ncurses or how to do it, will it allow me to get active input from the user in the input screen, while having the other two screens constantly be updated with messages and user names?

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,451
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help with ncurses
    By rakesh_01 in forum C Programming
    Replies: 2
    Last Post: 08-31-2009, 05:05 AM
  2. ncurses and fork
    By MK27 in forum Linux Programming
    Replies: 2
    Last Post: 10-05-2008, 08:55 PM
  3. Ncurses Lib
    By lautarox in forum C Programming
    Replies: 6
    Last Post: 09-24-2008, 06:12 PM
  4. Ncurses or not?
    By Zarniwoop in forum C Programming
    Replies: 4
    Last Post: 05-04-2008, 11:19 AM
  5. nCurses
    By MethodMan in forum Linux Programming
    Replies: 6
    Last Post: 02-18-2003, 06:29 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21