CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Win32 Programming Help:
Client Server Connection through sockets issue.

 



manishm
New User

Aug 11, 2010, 5:16 AM

Post #1 of 2 (9969 views)
Client Server Connection through sockets issue. Can't Post

 
I am new into sockets programming through perl:

I have the following server.pl


Code
#!C:\Perl\bin\perl 

use strict;
use Socket;

print "Content-type:text/html\n\n";
print "<html>\n";
print "<ul>";

# use port 7890 as default
my $port = shift || 7890;
my $proto = getprotobyname('tcp');
my $paddr = sockaddr_in($port, INADDR_ANY);

# create a socket, make it reusable
socket(SOCKET, PF_INET, SOCK_STREAM, $proto)
or die "Can't open socket $!\n";
setsockopt(SOCKET, SOL_SOCKET, SO_REUSEADDR, 1)
or die "Can't set socket option to SO_REUSEADDR $!\n";

# bind to a port, then listen
bind( SOCKET, $paddr)
or die "Can't bind to port $port! \n";
listen(SOCKET, 5) or die "listen: $!";
print "<li>SERVER started on port $port\n";

# accepting a connection
my $client_addr;
while ($client_addr = accept(NET_SOCKET, SOCKET)) {
# send them a message, close connection
print NEW_SOCKET "Smile from the server";
close NEW_SOCKET;
}

print "</ul>";
print "</html>\n";


and the following client.pl


Code
#!C:\Perl\bin\perl 

use strict;
use Socket;

print "Content-type:text/html\n\n";
print "<html>\n";
print "<ul>";

# initialize host and port
my $host = shift || 'localhost';
my $port = shift || 7890;
my $server = "localhost";
my $iaddr = inet_aton($host);
my $paddr = sockaddr_in($port, $iaddr);

# create the socket, connect to the port
socket(SOCKET,PF_INET,SOCK_STREAM,(getprotobyname('tcp')))
or die "Can't create a socket $!\n";

connect( SOCKET, $paddr)
or die "Can't connect to port $port! \n";

my $line;
while ($line = <SOCKET>) {
print "$line\n";
}
close SOCKET or die "close: $!";

print "</ul>";
print "</html>\n";


But I am unable to connect the client to the server. Do please let me know the areas I need to look into.

Thanks & Regards,
Manish.


sun9
New User

Nov 4, 2010, 11:56 AM

Post #2 of 2 (8839 views)
Re: [manishm] Client Server Connection through sockets issue. [In reply to] Can't Post

Hi Manishm,

i am new to socket programming. Please let me some resources from where i can learn socket programming.

I have a client server connection of computers. And i have to know the list of all process that are running on the client machines from the host machines.

For this reason i want to learn network programming with Perl.

Thanks in Advance.

Sun9

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives