Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > sockets

Reply
Thread Tools

sockets

 
 
someone
Guest
Posts: n/a
 
      01-18-2004
is there a way i can check whether there is any data in a tcp socket and to
check whether the socket has closed or not

for example

$line = <SOCKET>;

if the party at the other end does not send data, then the program will hang
at this point until data arrives. if there is data, how to know the size? i
want to read whatever that is available.


 
Reply With Quote
 
 
 
 
Rocco Caputo
Guest
Posts: n/a
 
      01-18-2004
On Sun, 18 Jan 2004 20:41:04 +0800, someone wrote:
> is there a way i can check whether there is any data in a tcp socket and to
> check whether the socket has closed or not
>
> for example
>
> $line = <SOCKET>;
>
> if the party at the other end does not send data, then the program will hang
> at this point until data arrives. if there is data, how to know the size? i
> want to read whatever that is available.


The select() function, conveniently wrapped by the IO::Select module,
will let you wait for data on a socket without necessarily blocking.

sysread() will read whatever is available on the socket, up to a
specified limit.

If you want input by lines, you will need to gather data in a buffer and
find the newlines therein. Buffered I/O like <SOCKET> is not compatible
with select(), and the documentation for select() will mention this.

See:

perldoc IO::Select
perldoc -f sysread
perldoc -f syswrite
perldoc -f select
_Perl Cookbook_ (which has good examples of these things)

--
Rocco Caputo - - http://poe.perl.org/
 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Carriage Returns and sockets Iceberg Perl 1 09-06-2003 04:49 PM
UNIX Domain Sockets Didatus Perl 1 08-18-2003 04:50 PM
Re: System.Net.Sockets.Tcplistener Gaurav Khanna [.NET MVP] ASP .Net 0 07-25-2003 12:34 PM
Re: System.Net.Sockets.Tcplistener Rick ASP .Net 0 07-17-2003 08:06 PM
Re: System.Net.Sockets.Tcplistener jeff ASP .Net 0 07-17-2003 02:09 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57