Current location: Hot Scripts Forums » Programming Languages » Perl » Simple Perl Server, need help.


Simple Perl Server, need help.

Reply
  #1 (permalink)  
Old 09-18-04, 06:26 PM
Lachy Lachy is offline
New Member
 
Join Date: Sep 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Simple Perl Server, need help.

Code:
#!/usr/bin/perl
my $i=1;
my $x;
my @connection=();
my $socket_handle;
use IO::Socket;
my $listen_socket = new IO::Socket::INET
(
LocalHost  => 'my ip(removed)',
LocalPort  => 500,
Proto      => 'tcp',
Listen     => 20,
Reuse      => 1,
);
while (1)
{
  if ($connection[$i] = $listen_socket->accept) { $i++; print "Accepting connection.\n"; }
  for($x=1;$x<=$i;$x++) {
    $socket_handle=$connection[$i];
    while ( $_ = <sock_handle> )
    {
      chomp;
      send $socket_handle, "Commanded received: ",$_,"\n";
      print "Sending data: ",$_,"\n";
    }
  }
}
close $listen_socket;
exit;
Can anybody tell me what's wrong?
It's accepting the connections just fine, but it won't return the commands I send it.

Thanks in advance,
Lachy.
Reply With Quote
  #2 (permalink)  
Old 09-18-04, 07:55 PM
Lachy Lachy is offline
New Member
 
Join Date: Sep 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Sorry, <sock_handle> there should be <$socket_handle>. Still doesn't work, however.
Reply With Quote
  #3 (permalink)  
Old 09-18-04, 10:24 PM
Chas Chas is offline
Coding Addict
 
Join Date: Oct 2003
Location: California
Posts: 359
Thanks: 0
Thanked 0 Times in 0 Posts
Hey Lachy,

Are you just seeing the "Accepting connection." on STDOUT? Going over the code quickly it looks like you have $i set to 1 here:


Code:
if ($connection[$i] = $listen_socket->accept) { $i++; print "Accepting connection.\n"; }
then increment it to 2. When trying to access to the connection again at that index here:


Code:
$socket_handle = $connection[$i];
you are trying to access it with 2 when you should be using 1, no?. Other than that, I don't see anythign glaring wrong with it. Have you tried using strict and warnings?

~Charlie
Reply With Quote
  #4 (permalink)  
Old 09-18-04, 10:27 PM
Chas Chas is offline
Coding Addict
 
Join Date: Oct 2003
Location: California
Posts: 359
Thanks: 0
Thanked 0 Times in 0 Posts
Actually, I think you want to be using $x instead if $i here:

Code:
$socket_handle = $connection[$x]
~Charlie
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Download files from another server using script! benweston Script Requests 5 01-17-06 09:29 AM
Free web site, control panel, and dedicated IP with game server purchase for only $25 twastudios General Advertisements 3 10-20-05 06:13 AM
Perl coder needed XGamingZone Perl 1 09-17-04 07:19 AM
Please Help ! sweetgurl Everything Java 2 04-13-04 11:57 AM
FREE Team Speak server w/ every purchase of a Call of Duty Server twastudios General Advertisements 0 10-31-03 01:14 AM


All times are GMT -5. The time now is 03:58 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.