Article View: be.comp.programming
Article #2035Nog eens perl
From: Nitro
Date: Tue, 26 Oct 2004 12:20
Date: Tue, 26 Oct 2004 12:20
66 lines
2586 bytes
2586 bytes
ik heb een nieuw probleem in perl:
ik heb mijn code (zie onderaan) om te connecten met een client op een
server. Alles gaat normaal, tot in de eerste lus, aan de lijn:
print("ready to accept");
Deze lijn verschijnt pas van zodra er een client geconnect heeft, niet
ervoor.
De lijn print("Client connected"); wordt zelfs helemaal niet weergegeven.
Ook kan ik maar met 1 client tegelijk connecten. De tweede is wel
connected, maar doet gewoon niets.
Ik gebruik telnet om dit te testen.
Nu heeft men mij verteld dat perl niet altijd alles uitvoert in de
volgorde dat het gecodeerd is, maar ik zou niet weten hoe ik dit kan
oplossen.
graag enige hulp...
Nitro
#!/usr/bin/perl
use warnings;
use strict;
use Socket;
use Thread;
socket(HANDLE, PF_INET, SOCK_STREAM, getprotobyname('tcp'));
print("TCP socket created ...\n");
bind(HANDLE, sockaddr_in(5000, INADDR_ANY));
print("Binding socket to port 5000 ...\n");
listen(HANDLE, 10);
print("Listening for connections ...\n");
my @threads;
# accepteert connecties en geeft die door aan Thread Tclient
while(1)
{
print("ready to accept");
accept(my $CLIENT, HANDLE);
print("Connection accepted ($CLIENT).\nStarting new thread ...\n");
push(@threads, new Thread(Tclient($CLIENT)));
}
# 1 thread per client: authenticatie, ...
sub Tclient
{
my($conn) = @_;
print("Client connected");
my $in;
while($in = <$conn>)
{
send($conn, "blabla", 0);
}
}
Technical Details
Message-ID:
<pan.2004.10.26.12.20.48.391470@skynet.be>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!syros.belnet.be!ikaria.belnet.be!news.belnet.be!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: fcea4,31b1eaf4342c808c,start X-Google-Attributes: gidfcea4,public X-Google-Language: DUTCH,ASCII-7-bit Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!syros.belnet.be!ikaria.belnet.be!news.belnet.be!not-for-mail From: Nitro <nitroglycerine@skynet.be> Newsgroups: be.comp.programming Subject: Nog eens perl Date: Tue, 26 Oct 2004 14:20:48 +0200 Organization: KULeuvenNet Lines: 67 Message-ID: <pan.2004.10.26.12.20.48.391470@skynet.be> NNTP-Posting-Host: seven.kulnet.kuleuven.ac.be Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: ikaria.belnet.be 1098793246 25354 134.58.127.12 (26 Oct 2004 12:20:46 GMT) X-Complaints-To: abuse@belnet.be NNTP-Posting-Date: Tue, 26 Oct 2004 12:20:46 +0000 (UTC) User-Agent: Pan/0.14.2.91 (As She Crawled Across the Table (Debian GNU/Linux)) Cache-Post-Path: seven.kulnet.kuleuven.ac.be!unknown@bluebird.kotnet.org X-Cache: nntpcache 2.4.0b5 (see http://www.nntpcache.org/)