single threaded application, that selects between stdin and a listeningsocket.

K

Klaus

Hi,



I would like to write a non blocking single threaded application in
Linux, that:

1.) acts as a single client TCP server. (no forks)
A user should be able to connect to a port, and send a command

2.) reads data from stdin


Reading via the socket and stdin should be non blocking.
Therefore I guess, that I should use the select() (or perhaps poll())
command.

I do know how to use select() as soon as a client has connected,
but I don't know how to wait ( listen() ) and still be able to treat
input from stdin.

Any hints?


Thanks in advance and bye


Klaus



This is a pseudo sceleton of a main function:

main(){

int clientconnected=0;



while(!end){
if(!clientconnected){
select_call(stdin,listensocket); // THAT'S WHERE I NEED
// HELP
if(datafromstdin){
treatstdin();
}
if(listendata_available){
sock=accept(listensocket,...);
clientconnected=1;
}
} else {
select_call(stdin_socket);
ifif(datafromstdin){
treatstdin();
}
if (datafromsocket){
treatsocketdata();
}
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top