Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Dec 2nd, 2005, 10:20 PM   #1
ProjectX
Programmer
 
ProjectX's Avatar
 
Join Date: Feb 2005
Posts: 37
Rep Power: 0 ProjectX is on a distinguished road
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.
and I dont know how to fix it.
ProjectX is offline   Reply With Quote
Old Dec 2nd, 2005, 10:53 PM   #2
sykkn
Hobbyist Programmer
 
Join Date: Apr 2004
Location: Texas
Posts: 106
Rep Power: 5 sykkn is on a distinguished road
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! */
sykkn is offline   Reply With Quote
Old Dec 2nd, 2005, 11:10 PM   #3
ProjectX
Programmer
 
ProjectX's Avatar
 
Join Date: Feb 2005
Posts: 37
Rep Power: 0 ProjectX is on a distinguished road
thanks alot syk
ProjectX is offline   Reply With Quote
Old Dec 8th, 2005, 1:33 PM   #4
ProjectX
Programmer
 
ProjectX's Avatar
 
Join Date: Feb 2005
Posts: 37
Rep Power: 0 ProjectX is on a distinguished road
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.
ProjectX is offline   Reply With Quote
Old Dec 27th, 2005, 9:58 AM   #5
swestres
Newbie
 
Join Date: Dec 2005
Posts: 13
Rep Power: 0 swestres is on a distinguished road
Sure, just put
while (<$socket>) {
  print;
}
at the end. Then all you have to do is to read RFC2616, learn some GUI programming and you've got yourself a webbrowser written in perl
__________________
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.
swestres is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

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 On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:47 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC