M
Martin Kissner
Hello together,
I am trying to write a little tcp-server which creates a write only
socket an test it with a little client.
The code I have tried so far is below and it workes as expected in the
form I posted it.
The question is:
Why do I have to shutdown(0) $session _and_ $socket on the server?
I had expected that the client would not be able to write to his $socket
if only $session on the server was shutdown(0)
--- server code ---
#!/usr/bin/perl
use warnings;
use strict;
use IO::Socket;
my $socket = IO::Socket::INET->new(
Listen => 1,
LocalPort => 1025,
Proto => 'tcp',
Reuse => 1);
my $session = $socket->accept;
$socket->shutdown(0) or die; ### Question is here !
$session->shutdown(0) or die; ### Question is here !
while(1) {
print $session "I don't read!\n";
my $read = $session->getline or die "I can not read\n: $!\n";
print $read;
sleep 1;
}
--- --- ---
--- client code ---
#!/usr/bin/perl
use warnings;
use strict;
use IO::Socket;
my $socket = IO::Socket::INET->new(
PeerHost => 'localhost',
PeerPort => 1025,
Proto => 'tcp') or die "Keine Verbindung\n";
my $line;
while (my $line = $socket->getline) {
print $line;
print $socket "I try to write\n" or die "I can not write: $!\n";
}
--- --- ---
I am trying to write a little tcp-server which creates a write only
socket an test it with a little client.
The code I have tried so far is below and it workes as expected in the
form I posted it.
The question is:
Why do I have to shutdown(0) $session _and_ $socket on the server?
I had expected that the client would not be able to write to his $socket
if only $session on the server was shutdown(0)
--- server code ---
#!/usr/bin/perl
use warnings;
use strict;
use IO::Socket;
my $socket = IO::Socket::INET->new(
Listen => 1,
LocalPort => 1025,
Proto => 'tcp',
Reuse => 1);
my $session = $socket->accept;
$socket->shutdown(0) or die; ### Question is here !
$session->shutdown(0) or die; ### Question is here !
while(1) {
print $session "I don't read!\n";
my $read = $session->getline or die "I can not read\n: $!\n";
print $read;
sleep 1;
}
--- --- ---
--- client code ---
#!/usr/bin/perl
use warnings;
use strict;
use IO::Socket;
my $socket = IO::Socket::INET->new(
PeerHost => 'localhost',
PeerPort => 1025,
Proto => 'tcp') or die "Keine Verbindung\n";
my $line;
while (my $line = $socket->getline) {
print $line;
print $socket "I try to write\n" or die "I can not write: $!\n";
}
--- --- ---