11 Replies - 1127 Views - Last Post: 30 March 2011 - 07:09 AM

#1 jbeme  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 93
  • Joined: 30-October 09

Socket, Perl, Apache2, Ubuntu setup question

Posted 26 March 2011 - 10:59 PM

Basically, I need the help of a good tutorial or perhaps someone will know what I am missing. Anyways, here we go.
I am running Ubuntu 10.10 with Apache2 and libio-socket-ssl-perl and perl installed. I have a private network setup between the two via a cable and two eth cards. From comp 1 I can ping comp 2 or view the basic intro web page apache2 sets up, I can also run a basic perl program I set up that simple says "Hello".
Now when attempting to follow the instructions http://www.tutorials...perl_socket.htm or http://www.devshed.c...ming-in-PERL/2/ or http://search.cpan.o...tFactory.pm#new or a few other places, I can not for the life of me get it to bind, connect, or any other form of it working. I would like to set up a single in port and shut off everything else on the server computer (including working without Apache, as it seems there should be a way to force the perl to listen).
Pretty new to Linux based systems. Thanks.

This post has been edited by jbeme: 26 March 2011 - 11:07 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Socket, Perl, Apache2, Ubuntu setup question

#2 jbeme  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 93
  • Joined: 30-October 09

Re: Socket, Perl, Apache2, Ubuntu setup question

Posted 29 March 2011 - 09:32 PM

Figured I would add a good tutorial/example now that I have found one that works with my system.
http://cs.uno.edu/~golden/teach.html
the server and client examples also include a lot of side notes that explain everything. As of now I have my client creating a socket to the correct addr, binds, then fails to finalize the connection. So working on that, just happy to have my log showing something useful now.

This post has been edited by jbeme: 29 March 2011 - 09:32 PM

Was This Post Helpful? 0
  • +
  • -

#3 no2pencil  Icon User is offline

  • Head MFIC
  • member icon

Reputation: 5066
  • View blog
  • Posts: 26,449
  • Joined: 10-May 07

Re: Socket, Perl, Apache2, Ubuntu setup question

Posted 29 March 2011 - 09:34 PM

What user permissions are you running the perl socket with? A standard user is not going to be able to bind a socket (on the server). Try again as root.
Was This Post Helpful? 1
  • +
  • -

#4 jbeme  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 93
  • Joined: 30-October 09

Re: Socket, Perl, Apache2, Ubuntu setup question

Posted 29 March 2011 - 09:44 PM

Maybe someone can answer this. My server add is say 10.1.101.11, the client add is 10.1.101.10. The client also has an address of say 192.168.0.1 on the network that is exposed to the internet, Apache2 is also set up to connect on the 192.168.0.1 network and localhost for that computer is via that connection.
Ok, so if I put the addr of the server to 10.1.101.11 and connect to a port on that server it should connect right?
Or do I need some way to tell it to work another network (since the client default is the public side).

root from the terminal.
Was This Post Helpful? 0
  • +
  • -

#5 no2pencil  Icon User is offline

  • Head MFIC
  • member icon

Reputation: 5066
  • View blog
  • Posts: 26,449
  • Joined: 10-May 07

Re: Socket, Perl, Apache2, Ubuntu setup question

Posted 29 March 2011 - 09:46 PM

Which ip addresses successfully ping one another? The 192.168.x.x & 10.x.x.x are different subnets.
Was This Post Helpful? 1
  • +
  • -

#6 jbeme  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 93
  • Joined: 30-October 09

Re: Socket, Perl, Apache2, Ubuntu setup question

Posted 29 March 2011 - 09:49 PM

root, terminal from client. Then on the server I have permission set to allow execution by users and modify/execute by root. Should I change both to modify and execute?

From system>pref>network connections, they can ping each other. 3-4ms delay

This post has been edited by jbeme: 29 March 2011 - 09:50 PM

Was This Post Helpful? 0
  • +
  • -

#7 no2pencil  Icon User is offline

  • Head MFIC
  • member icon

Reputation: 5066
  • View blog
  • Posts: 26,449
  • Joined: 10-May 07

Re: Socket, Perl, Apache2, Ubuntu setup question

Posted 29 March 2011 - 09:49 PM

I don't see any ip address information in that post. Which ip addresses successfully ping one another?
Was This Post Helpful? 0
  • +
  • -

#8 jbeme  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 93
  • Joined: 30-October 09

Re: Socket, Perl, Apache2, Ubuntu setup question

Posted 29 March 2011 - 09:54 PM

here terminal output:)
[1] 2911
usage: sudo -h | -K | -k | -L | -V
usage: sudo -v [-AknS] [-p prompt]
usage: sudo -l[l] [-AknS] [-g groupname|#gid] [-p prompt] [-U username] [-u
            username|#uid] [-g groupname|#gid] [command]
usage: sudo [-AbEHknPS] [-C fd] [-g groupname|#gid] [-p prompt] [-u
            username|#uid] [-g groupname|#gid] [VAR=value] [-i|-s] [<command>]
usage: sudo -e [-AknS] [-C fd] [-g groupname|#gid] [-p prompt] [-u
            username|#uid] file ...
Content-type:text/html 

Using port 6668 to connect to server on host 10.1.101.12...
Socket creation succeeded.
Bind succeeded.
Connection timed out at /usr/lib/cgi-bin/client.pl line 76.
[1]+  Exit 1                  sudo




This is the code that fails.

if (connect(S, $that)) {
    print "Connect succeeded.\n";
}
else {
    die $!;# line 76
}



Ok and a ping
PING 10.1.101.11 (10.1.101.11) 56(84) bytes of data.
64 bytes from 10.1.101.11: icmp_req=1 ttl=64 time=0.022 ms
64 bytes from 10.1.101.11: icmp_req=2 ttl=64 time=0.019 ms
64 bytes from 10.1.101.11: icmp_req=3 ttl=64 time=0.024 ms
64 bytes from 10.1.101.11: icmp_req=4 ttl=64 time=0.022 ms




This post has been edited by jbeme: 29 March 2011 - 10:03 PM

Was This Post Helpful? 0
  • +
  • -

#9 jbeme  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 93
  • Joined: 30-October 09

Re: Socket, Perl, Apache2, Ubuntu setup question

Posted 29 March 2011 - 10:04 PM

ahh just realized the client is trying to connect to itself...
Was This Post Helpful? 0
  • +
  • -

#10 no2pencil  Icon User is offline

  • Head MFIC
  • member icon

Reputation: 5066
  • View blog
  • Posts: 26,449
  • Joined: 10-May 07

Re: Socket, Perl, Apache2, Ubuntu setup question

Posted 29 March 2011 - 10:09 PM

Glad you got it figured out!
Was This Post Helpful? 0
  • +
  • -

#11 jbeme  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 93
  • Joined: 30-October 09

Re: Socket, Perl, Apache2, Ubuntu setup question

Posted 30 March 2011 - 05:56 AM

Ok so bit further along now, but once again stuck.
Here is what I got. When I ping from comp 1 terminal (10.1.101.11).
or the client.pl (the code is at end) comp:
nc -z -v -w2 10.1.101.12 6668
Connection to 10.1.101.12 6668 port [tcp/*] succeeded!



comp 2 terminal or server.pl comp then displays:
Server connection 1 @ Internet address 10 1 101 11
Client went away. Forked server 1 exiting...



So thats all good. Now my problem is running the client program from the example will not connect to the server.
From Terminal:
 sudo & /usr/lib/cgi-bin/client.pl
[1] 4748
usage: sudo -h | -K | -k | -L | -V
usage: sudo -v [-AknS] [-p prompt]
usage: sudo -l[l] [-AknS] [-g groupname|#gid] [-p prompt] [-U username] [-u
            username|#uid] [-g groupname|#gid] [command]
usage: sudo [-AbEHknPS] [-C fd] [-g groupname|#gid] [-p prompt] [-u
            username|#uid] [-g groupname|#gid] [VAR=value] [-i|-s] [<command>]
usage: sudo -e [-AknS] [-C fd] [-g groupname|#gid] [-p prompt] [-u
            username|#uid] file ...
Content-type:text/html 

Using port 6668 to connect to server on host 10.1.101.12...
Socket creation succeeded.
Bind succeeded.
Connection timed out at /usr/lib/cgi-bin/client.pl line 37.
[1]+  Exit 1                  sudo


client.pl
#!/usr/bin/perl	
use Socket;
($them,$port) = @ARGV;
$port = 6668 unless $port;
$them = '10.1.101.12';
$SIG{'Int'} = 'dokill';
sub dokill {
    kill 9, $child if $child;
}
chop($hostname = `hostname`);	
($name, $aliases, $proto) = getprotobyname('tcp');
($name, $aliases, $port) = getservbyname($port,'tcp')
    unless $port =~ /^\d+$/;
print "Using port $port to connect to server on host $them...\n";
($name,$aliases,$type,$len,$thisaddr) = gethostbyname($hostname);
($name, $aliases,$type,$len,$thataddr) = gethostbyname($them);
if (socket(S,AF_INET, SOCK_STREAM, $proto)) {
    print "Socket creation succeeded.\n";
}
else {
    die $!;
}
$sockaddr = 'S n a4 x8';
$this = pack($sockaddr, AF_INET, 0, $thisaddr);
$that = pack($sockaddr, AF_INET, $port, $thataddr);
if (bind(S, $this)) {
    print "Bind succeeded.\n";
}
else  {
    die $!;
}
if (connect(S, $that)) {
    print "Connect succeeded.\n";
}


server.pl
#!/usr/bin/perl use Socket; 
($port) = @ARGV; 
$port = 6668 unless $port; 
($name, $aliases, $protocol) = getprotobyname('tcp'); 
if ($port !~ /^\d+$/) { 
($name, $aliases, $port) = getservbyport($port, 'tcp'); 
} 
print "Listening on port $port...\n"; 
socket(S,AF_INET,SOCK_STREAM,$protocol) || die "socket : $!"; 
$sockaddr = 'S n a4 x8'; 
$this = pack($sockaddr, AF_INET, $port, "\0\0\0\0"); 
bind(S, $this) || die "bind : $!"; 
listen(S,10) || die "listen: $!"; select(S); 
$| = 1; 
select(STDOUT); 
for ($con = 1; ; $con++) { 
printf("Waiting for connection %d....\n", $con); 
($addr = accept(NS,S)) || die $!; 
select(NS); 
$| = 1; 
select(STDOUT); 
if (($child = fork()) == 0) { 
($af,$port, $inetaddr) = unpack($sockaddr, $addr); 
@inetaddr = unpack('C4', $inetaddr); 
print "Serving connection $con @ Internet address @inetaddr\n";
 while () { 
print "Received from client $con: $_"; 
print NS "Server $con: $_"; 
} 
close(NS); 
print "Client went away. Forked server $con exiting...\n"; 
exit; 
} 
close(NS); 
}



So yeah 99% taken from the example. Maybe someone can help me with what I am missing.

This post has been edited by jbeme: 30 March 2011 - 06:01 AM

Was This Post Helpful? 0
  • +
  • -

#12 jbeme  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 93
  • Joined: 30-October 09

Re: Socket, Perl, Apache2, Ubuntu setup question

Posted 30 March 2011 - 07:09 AM

Well once again never mind. I got a client I sort of strung together but it can connect to the server. Now I just need to learn to send strings.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1