ecuguru has asked for the wisdom of the Perl Monks concerning the following question:
Stumped. Any help appreciated.thread failed to start: Can't use an undefined value as a symbol refer +ence at server_client_thread.pl line 18, <GEN1> line 4.
#!/usr/bin/perl -w use strict; use threads; use threads::shared; use IO::Socket; use Net::hostent; my $controlSocket; my $server; my $controlSocketThread = threads->new (\&commandPath); my $serverHostThread = threads->new (\&serverStart); sleep(); ##Talk to the command server sub sendServer(){ my $buff = $_[0]; print "I am sending from Client to controlServer: $buff\n"; print $controlSocket "$buff\n"; ##Code Dies Here $controlSocket->autoflush(); } ##Talk back to the client who connected (initiated from server) sub sendClient(){ my $buff = $_[0]; printf $server ("$buff"); $server->autoflush(); print "<---$buff"; } ##This initiates command to the Control Server sub commandPath { while (1){ $controlSocket = IO::Socket::INET->new("localhost:1024") or pr +int "Can`t open feed\n"; if (defined($controlSocket)){ last; } } print "-->HBAK\n"; print $controlSocket "HBAK\n"; print $controlSocket "STREAM\n"; while ( <$controlSocket> ) { print "I got $_"; if (defined($server)){ &sendClient("I got $_\n"); } } } ##clients connect through this function sub serverStart(){ my $port= 2048; $server = IO::Socket::INET->new( Proto => 'tcp', LocalPort => $port, Listen => SOMAXCONN, Reuse => 1); die "can't setup server" unless $server; print "[Server $0 is running]\n"; while ($server = $server->accept()) { $server->autoflush(1); my $hostinfo = gethostbyaddr($server->peeraddr); printf "[Connect from %s]\n", $hostinfo->name || $server-> +peerhost; &sendClient ("HELO\n"); #Say hi to everyone who connects while ( <$server>) { print "Client requested $_\n"; next unless /\S/; # blank line if (/quit|exit/i) { last;} elsif (/RELAY/i) { &sendClient("Sending to Server\n"); &sendServer("RELAY\n"); } elsif (/STARTING/i) { } else { print $server "Command unknown $_"; } } } close $server; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Threaded Sockets, access from outside thread?
by BrowserUk (Patriarch) on Jun 16, 2006 at 07:48 UTC | |
by ecuguru (Monk) on Jun 19, 2006 at 01:38 UTC | |
|
Re: Threaded Sockets, access from outside thread?
by Anonymous Monk on Jun 16, 2006 at 05:35 UTC | |
by ecuguru (Monk) on Jun 16, 2006 at 05:40 UTC | |
by ikegami (Patriarch) on Jun 16, 2006 at 05:44 UTC | |
by ecuguru (Monk) on Jun 16, 2006 at 06:10 UTC |