![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Feb 2005
Posts: 37
Rep Power: 0
![]() |
Sockets
Hey guys its me again. Sorry if I am getting annoying with all the post i did but I need help.So I started to practice with sockets so i made a script that opens a port and listens on it.
#!C:/PERL/BIN/perl.exe -w
#
use IO::Socket;
my $sock = new IO::Socket::INET (LocalHost => '192.168.1.100',
LocalPort => '1337',
Proto => 'tcp',
Listen => 1,
Reuse => 1,);
die "Could not create socket: $!\n" unless $sock;
my $newsock = $sock -> accept();
while (defined(<newsock>)) {
print $_;
}
close($sock);and it gives me this error: Name "main::newsock" used only once: possible typo at C:\DOCUME~1\User\MYDOCU~1\PERLPR~1\Sockets\Socket~1.PL line 11. |
|
|
|
|
|
#2 |
|
Hobbyist Programmer
Join Date: Apr 2004
Location: Texas
Posts: 106
Rep Power: 5
![]() |
you left the $ off of newsock in your while test .... also ... you can leave off the defined() call ... it mucks up the input anyway ...
while (<$newsock>) {
print $_;
}
__________________
[ [ SykkN alloc ] initWithThePowerTo: destroyYouAll ]; /* Don't make me use it! */ |
|
|
|
|
|
#3 |
|
Programmer
Join Date: Feb 2005
Posts: 37
Rep Power: 0
![]() |
thanks alot syk
|
|
|
|
|
|
#4 |
|
Programmer
Join Date: Feb 2005
Posts: 37
Rep Power: 0
![]() |
is there a way to print the output of what the server will print. Like lets say i got this code
use IO::Socket; $socket = IO::Socket::INET -> new (PeerAddr => "www.host.com", PeerPort => 80, Proto => "tcp") || die "Can't connect to the host"; print $socket "Hello, There!\n"; So is there a way to print on my screen what the www.host.com will print on his like Unrecongnized commnad or just a plain window or Premission Denied. |
|
|
|
|
|
#5 |
|
Newbie
Join Date: Dec 2005
Posts: 13
Rep Power: 0
![]() |
Sure, just put
while (<$socket>) {
print;
}![]()
__________________
Here comes the SWAT team, and the M-16, shoot the walls in, destroy the building. Wolverine was sad and it made him mad, every single cop got a bullet in the head. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|