Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Socket Question

by perlsyntax (Pilgrim)
on Nov 28, 2007 at 23:31 UTC ( [id://653711]=perlquestion: print w/replies, xml ) Need Help??

perlsyntax has asked for the wisdom of the Perl Monks concerning the following question:

How can i connect to a remote sever do i have to use IO:Sockets?

Replies are listed 'Best First'.
Re: Socket Question
by Joost (Canon) on Nov 28, 2007 at 23:52 UTC
Re: Socket Question
by RaduH (Scribe) on Nov 28, 2007 at 23:42 UTC
    Assuming TCP connection to some server (sshd on port 22 in the example below), here's an example:
    ... my $remoteIP ='a.b.c.d'; my $port = 22; #aiming for sshd - use your own port here my $iaddr = inet_aton($remoteIP) || die("No $remoteIP around"); my $paddr = sockaddr_in($port, $iaddr); my $protocol = getprotobyname('tcp'); socket(SOCK, PF_INET, SOCK_STREAM, $protocol) || die("socket() fai +led: $!"); connect(SOCK, $paddr) || die("connect() failed: $!"); $line = <SOCK>; #read a line print("$line online\n"); #print it close(SOCK); #close socket ...
Re: Socket Question
by Cubes (Pilgrim) on Nov 28, 2007 at 23:35 UTC
    What kind of server?

    There are pre-built CPAN modules available that will help you connect to a variety of common servers (HTTP, SMTP, FTP, and so on).

      Like any network server it don't matter.:)
        A Client and a Server have to agree on certain things before they start to communicate with each other. The first is the communications protocol they'll use. (The most common these days is TCP/IP. Ten years ago it was X.25 . IBM wishs the world used SNA, which was popular 20 years ago.)

        Then you both have to agree how you'll exchange information using that communications protocol. Financial institutions now use something called FIX. The Stock Exchanges used to use proprietary message formats. Then you have to worry about the character set you communicate in...

        So communications prgramming is very, very specific , very detail-oriented.
        For some network servers it "DO" matter ... Much to your surprise, you might discover one day not everyone is using what I suspect you assume to be universal (which I think you think it is TCP/IP). The other questions/comments make sense and my answer is an example assuming TCP ...
Re: Socket Question
by zentara (Archbishop) on Nov 29, 2007 at 14:34 UTC
    Check out the Perl examples at UNO examples ; but as others have said, you will manually need to figure out the protocol for the different server types that you want to connect to.

    I'm not really a human, but I play one on earth. Cogito ergo sum a bum

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://653711]
Approved by Old_Gray_Bear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (11)
As of 2024-04-19 16:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found