Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

combining STDIN and a socket

Status
Not open for further replies.

fykosak

Programmer
Dec 17, 2001
11
CZ
Hi guys,
I'm working on an ICQ client written in pure perl and I need to create kind of loop, which would test if there's something comaing from a socket and than if there's something at the STDIN. The problem is that it gots stuck waiting for the STDIN. Select doesn't seem to work properly with that. Any ideas?
robin
 
Robin,

It would probably be easier to write if you use more than one process; one process would listen for incoming chars and displays them on, say, the top of the screen. The other process listens for keystrokes, displays them at the bottom of the screen and sends the data to the other person.

You could use fork() to split your perl script into two processes, the general structure of your script would look something like this:
[tt]
if(fork(){
[tab]WaitForDataAndDisplay();
} else {
[tab]WaitForKeyStrokesAndDisplayAndSend();
}

sub WaitForDataAndDisplay(){
[tab]# You can write this bit...
}
sub WaitForKeyStrokesAndDisplayAndSend(){
[tab]# And this bit...
}
[/tt]

I wrote something like this a few years ago, worked ok. Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top