Thread Probleme mit Client (9 answers)
Opened by Gast at 2004-05-17 18:37

naich
 2004-05-18 19:34
#37019 #37019
User since
2004-05-17
8 Artikel
BenutzerIn
[default_avatar]
Der Server läuft ja auf IO::Select.

Code: (dl )
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
my $socket = new IO::Socket::INET (
LocalHost => $hostAddr,
LocalPort => $hostPort,
Proto => 'tcp',
Type => SOCK_STREAM,
Listen => SOMAXCONN,
Reuse => 1
) or die "*** Can't create server socket. ($!) ***\n" unless $socket;
print "*** Server listening on $hostAddr:$hostPort ... :-) ***\n";

my $allClients = new IO::Select($socket);
my @activeClients;

while (@activeClients = $allClients->can_read())
{
foreach my $client (@activeClients)
{
if ($client eq $socket)
{
my $newClient = $socket->accept(); # accept the connection
$allClients->add($newClient); # add it to the handler
print "*** ".$newClient->peerhost.":".$newClient->peerport." has just connected. ***\n";
}
else
{
my $nval = $client->recv(my $request, $maxBuffer, 0);
if (!defined($nval) || !length($request))
{
print "*** Connection has been closed. ***\n";
my $h = 0;
while ($activeUsers[$h])
{
if ($activeUsers[$h]->{'handle'} == $client)
{
splice(@activeUsers,$h,1);
}
$h++;
}
$allClients->remove($client);
$client->close();
next;
}
}
}
}



Aber wie sieht das auf der Client-Seite aus. Da kann ich ja nicht auf eigende Verbindungen warten.
So langsam verzweifele ich an dem Problem.

View full thread Probleme mit Client