in reply to How can I test TCP socket status in Perl?
Hello beanscake,
I think you can find more here: How to find out whether socket is still connected?.
But it would be good to provide us with more information, such as:
Sample of current output.
Operating system (Windows, Linux, Mac).
etc. anything you think relevant that can affect your question.
Update:
I executed your code and I got the following error:Connect failed: IO::Socket::INET: connect: Connection refusedI think you need to start with some basics first. Read first this sort tutorial Perl, Sockets and TCP/IP Networking that I used the sample code provided under:
Server:
#!/usr/bin/perl use warnings; use strict; use IO::Socket::INET; my $sock = new IO::Socket::INET ( LocalHost => '127.0.0.1', LocalPort => '7070', Proto => 'tcp', Listen => 1, Reuse => 1, ); die "Could not create socket: $!\n" unless $sock; my $new_sock = $sock->accept(); while(<$new_sock>) { print $_; } close($sock);
Client:
#!/usr/bin/perl use warnings; use strict; use IO::Socket::INET; my $sock = new IO::Socket::INET ( PeerAddr => '127.0.0.1', PeerPort => '7070', Proto => 'tcp', ); die "Could not create socket: $!\n" unless $sock; print $sock "Hello there!\n"; close($sock);
Output on Server:
Hello there!Hope this helps.
|
|---|