Re: Write-Only Socket
From: Martin Kissner (news_at_chaos-net.de)
Date: 02/23/05
- Next message: J M: "FTP from macro"
- Previous message: Anno Siegel: "Re: more backup script problems!?!"
- In reply to: xhoster_at_gmail.com: "Re: Write-Only Socket"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 23 Feb 2005 15:06:28 +0100
xhoster@gmail.com wrote :
> Martin Kissner <news@chaos-net.de> wrote:
>> The question is:
>> Why do I have to shutdown(0) $session _and_ $socket on the server?
>
> As far as I can tell, you don't. I get the same behavior whether $socket
> is shutdown or not.
Yes, now I get the same result. I can't reproduce the behaviour I had
last time when I tried.
>> I had expected that the client would not be able to write to his $socket
>> if only $session on the server was shutdown(0)
>
> I don't see that happening regardless of what you shutdown. It looks to me
> like the client is prohibited from writing to the socket only because
> server exits. shutdown(0) does not seem to be enforced on the other
> end of the socket.
Yes, that seems to be true.
I changed my server script so it will not die but warn if 'getline'
fails. Now I get another unexpected result. The server starts reading
from the socket after one loop (Code and output below).
Can anyone explain this?
How could I permanently close the socket for reading?
Here is the new code of the server:
----
#!/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;
$session->shutdown(0) or die;
while(1) {
my $read = $session->getline or warn "I can not read: $!\n";
print $read;
sleep 1;
}
-----
Here is the output after I had started the client (with comments)
--- start output ---
# first loop
I can not read:
Use of uninitialized value in print at ./server.pl line 22.
# second loop
Client tries to write
Client tries to write
Client tries to write
Client tries to write
# Here I killed the client
I can not read:
Use of uninitialized value in print at ./server.pl line 22, <GEN1> line 4.
I can not read:
Use of uninitialized value in print at ./server.pl line 22, <GEN1> line 4.
# Here I killed the server
^C
end output ---
Here is the client code (if anybody wants to try it him/herself)
--- 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 "Connection failed: $!\n";
while (1) {
print "Client is printing to socket\n" if print $socket "Client
tries to write\n"; sleep 1;
}
--- end ---
--
perl -e '$|=1;&p(7.74.117.115.116.32);&s();&p(97.110.111);&p(116.104.101
.114);&s;&p(32.112.101.114.108);&s();&p(32.104.97.99.107.101.114.10);sub
s{sleep 1};sub p(){print "@_"}'
- Next message: J M: "FTP from macro"
- Previous message: Anno Siegel: "Re: more backup script problems!?!"
- In reply to: xhoster_at_gmail.com: "Re: Write-Only Socket"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|