By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,847 Members | 1,336 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,847 IT Pros & Developers. It's quick & easy.

About Socket programming

100+
P: 129
Hello friends,
When i used the following code and run i have an error:
connect: Connection refused at sock.pl line 20.


The code is:


Expand|Select|Wrap|Line Numbers
  1. #!/bin/perl -w
  2. # Example of a TCP daytime client using perl calls directly
  3. use Socket qw(AF_INET SOCK_STREAM inet_aton sockaddr_in);
  4. # get protocol number
  5. $proto = getprotobyname("tcp");
  6. print "prototype=$proto\n";
  7. # create the generic socket
  8. socket(SOCK, AF_INET, SOCK_STREAM, $proto) or die "socket: $!";
  9. # no need for bind here
  10. # get packed address for host
  11. $addr = inet_aton("localhost");
  12. print "addr = $addr\n";
  13. # get port number for the daytime protocol
  14. $port = getservbyname("daytime", "tcp");
  15. print "port=$port\n";
  16. # pack the address structure for connect
  17. $paddr = sockaddr_in($port, $addr);
  18. print "paddr = $paddr\n";
  19. # connect to host
  20. connect(SOCK, $paddr) or die "connect: $!";
  21. # get and print the date
  22. print <SOCK>;
  23. # close the socket
  24. close(SOCK) || die "close: $!";


So,please help me friends.
Mar 18 '08 #1
Share this Question
Share on Google+
2 Replies


eWish
Expert 100+
P: 971
When you run the script do these two lines print the proper data?

Expand|Select|Wrap|Line Numbers
  1. print "addr = $addr\n";
  2. print "paddr = $paddr\n";
--Kevin
Mar 18 '08 #2

100+
P: 129
When you run the script do these two lines print the proper data?

Expand|Select|Wrap|Line Numbers
  1. print "addr = $addr\n";
  2. print "paddr = $paddr\n";
--Kevin
Hello friend, it is giving output like below:
addr = 
port=13
ddr = 
connect: Connection refused at sock.pl line 20.
Mar 19 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.