473,396 Members | 1,836 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

About Socket programming

129 100+
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
2 2180
eWish
971 Expert 512MB
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
sasimca007
129 100+
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

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

Similar topics

4
by: 0to60 | last post by:
I have a question about socket programming in general. Exactly what happens behind the scenes when I one socket connects to a different socket in listen mode? Using the dotnet framework, I...
1
by: mirandacascade | last post by:
Version of python: 2.4 O/S: Win2K I will be writing some python scripts to do some client-side programming that involves socket.py. I expect that I will be making calls to the following...
3
by: cocla | last post by:
I try to connect to server using following codes: (smart device application) Socket s=new Socket(); try { s.connect(host);//host is an object of IPEndPoint class } catch (SocketException) {
3
by: zbcong | last post by:
hello i found there are three socket programming architectures from dotnet:synchronized socket,asynchronized socket and TcpListener. i know that the asynchronized socket is non-blocking socket.i...
10
by: Uma - Chellasoft | last post by:
Hai, I am new to VB.Net programming, directly doing socket programming. In C, I will be able to map the message arrived in a socket directly to a structure. Is this possible in VB.Net. Can...
0
by: shonen | last post by:
I'm currently attempting to connect to a shoutcast server pull down the information from here and then I'll parse it. I got this working with the httplib, which was great, the problem is I want...
8
by: =?Utf-8?B?Sm9obg==?= | last post by:
Hi all, I am new to .net technologies. ASP.NET supports socket programming like send/receive in c or c++? I am developing web-site application in asp.net and code behind is Visual C#. In...
2
by: Dave Dean | last post by:
Hi all, I'm just starting out in sockets/network programming, and I have a very basic question...what are the 'security' implications of opening up a socket? For example, suppose I've written a...
3
by: Stuart | last post by:
I am in the process of teaching myself socket programming. I am "playing around" with some simple echo server-client programs for m the book TCP/IP Sockets in C. The Server program is: ...
5
by: fishfin | last post by:
I was working through a tutorial about how to write a server using python (the url is bellow). I am sure that the server is working to some degree because when the server is running localhost:8080...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.