
benchivers
Novice
Aug 17, 2002, 3:21 PM
Post #1 of 2
(758 views)
|
Sockets Problem (Networking)
|
Can't Post
|
|
I am trying to make a program which will try and connect to a remote computer or server, I can successfully create a new socket for the client, but when the client tries to connect an error returns "Connection Refused". My program code is display on this post, any ideas anyone? I am quite new to networking in perl, and the program I am trying to create is a CGI script to run on a server, if the user can successfully connect to the server I want to print "Connection Successful" if a server is unavailable to connect to I want to print "Connection Unsuccessful". Any help would be most helpful. Code: #!/usr/bin/perl use Socket; print "Content-type: text/html\n\n"; my ($server, $port, $proto, $serveraddr); $servername = "www.supersitespro.com"; $port = 2001; $port = getservbyname($port, 'tcp'); $server = gethostbyname($servername) || dienice("Unable to get host by name : $!"); $proto = getprotobyname('tcp'); $serveraddr = sockaddr_in($port, $server); if (socket(SOCK, PF_INET, SOCK_STREAM, $proto)){ print "Socket OK<br>"; } else{ print "Socket Failed<br>"; } connect(SOCK, $serveraddr) || print "Connection Failed : $!<br>"; close(SOCK); sub dienice{ my($msg) = @_; print "$msg"; exit; } Many Regards, Ben Chivers Wheres the damn coffee? zzzZZZZZ!!!
|