Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!elroy.jpl.nasa.gov!jpl-devvax!lwall From: lwall@jpl-devvax.jpl.nasa.gov (Larry Wall) Newsgroups: comp.lang.perl Subject: Re: Multiple simultaneous accepts with an array. Message-ID: <1991May3.175929.1441@jpl-devvax.jpl.nasa.gov> Date: 3 May 91 17:59:29 GMT References: Reply-To: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Organization: Jet Propulsion Laboratory, Pasadena, CA Lines: 30 In article ea08+@andrew.cmu.edu (Eric A. Anderson) writes: : I got no responses the last time I think I sent this out, and there : were problems with the netnews software at andrew at about that time, : so on the assumption that this did not succesfully make it out, I will : post it again. : -------------- : I am writing a program which I want to have listen on a port, and when : it gets connections, keep adding all the connections to a list. : So I wrote the following line : : ($addr = accept($DataSock[++$#DataSock],CONNSOCK)) || die $!; : Now what happens when this runs is that the first connection is opened : fine, but when a second connection comes in, the first one is killed. That's because you accepted them both on the null filehandle. accept() and open() do not generate filehandles--you have to do that yourself: $genhandle = "FH000"; # We'll increment this magically. ... $DataSock[++$#DataSock] = $handle = $genhandle++; ($addr = accept($handle,CONNSOCK)) || die $!; I think accept() and open() will take arbitrary expressions returning a filehandle, but many of the I/O operators require either a filehandle or a simple scalar variable holding a filehandle: $handle = $DataSock[$whatever]; print $handle $stuff; $stuff = <$handle>; Larry