LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 04-01-2004, 12:22 PM   #1
krajzega
Member
 
Registered: Jan 2004
Location: Poland
Distribution: FreeBSD 5.1
Posts: 92

Rep: Reputation: 15
Ncurses windows and sockets in asynch mode (?)


I would like to write something looking like irssi or bitchx using ncurses. I've prepared a few windows and the problem appears when I want to use window input and a loop, let's see (it's not full code , only a schema) :
fcntl(socket, ....); //sets a socket asynchronous mode
while(1) {
wgetstr(window, buffer) //it get's some data from user in one window
send(...); //sends input data to a socket
recv (....); //receives data from a socket
printf(received data); //prints this data to ther window
}

It's a bit stupid, because this application should still receive data from socket and in the same time from user. But it waait until user put some data and then receives something and print. It should look as a two different loops which are running in the same time. Any ideas?
 
Old 04-01-2004, 05:05 PM   #2
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,540

Rep: Reputation: 149Reputation: 149
You can make your program use two threads (one dealing with socket and the second one with user) or use 'select' to wait for first event.
 
Old 04-01-2004, 06:02 PM   #3
krajzega
Member
 
Registered: Jan 2004
Location: Poland
Distribution: FreeBSD 5.1
Posts: 92

Original Poster
Rep: Reputation: 15
I don't think that's good idea..because I won't put 2 applications in two different ncurses windows.
 
Old 04-02-2004, 03:17 PM   #4
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,540

Rep: Reputation: 149Reputation: 149
Threads are in one program, they can write to the same window and so on (but synchronization is needed). So probably 'select' would be better for you. It allows you to wait at the same for socket and user input.
 
Old 04-03-2004, 02:31 PM   #5
krajzega
Member
 
Registered: Jan 2004
Location: Poland
Distribution: FreeBSD 5.1
Posts: 92

Original Poster
Rep: Reputation: 15
It isnt also good idea, because:
wgetstr(...) means the same as:

while(char!='\n') {
getch(char);
add-char-to-buffer;
}
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Ncurses and full windows Ephracis Programming 4 11-08-2004 06:50 AM
ncurses windows leaving trails kamel Programming 0 06-03-2004 10:28 PM
Ncurses and a few windows krajzega Programming 1 05-13-2004 10:51 PM
WINDOWS in ncurses, newwin limbo Nevion Programming 6 12-10-2003 01:20 AM
are fs requests synch or asynch? jdt Linux - General 3 11-17-2003 01:47 PM


All times are GMT -5. The time now is 01:26 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration