Help me out to understand the socket programming.For passing data from one machine to another machine over TCP/IP protocol. What all basic things i have to take care for creating socket script?? Do I have to always run below server script on server end?? Is there any way to run server script remotely?? Is there any way to pass data across the machine running both server and client script at one machine only??

server script

use IO::Socket; my $sock = new IO::Socket::INET ( LocalHost => 'localhost', LocalPort => '7890', Proto => 'tcp', Listen => 1, Reuse => 1, ); die "Could not create socket: $!\n" unless $sock; my $new_sock = $sock->accept(); while(<$new_sock>) { print $_; } close($sock);

client script

use IO::Socket; my $sock = new IO::Socket::INET ( PeerAddr => 'localhost', PeerPort => '7890', Proto => 'tcp', ); die "Could not create socket: $!\n" unless $sock; my @val = qw(Hello there! this is socket); print $sock @val; close($sock);

sorry I was not very much cleared my problem above

actually my requirement is simple to pass data from one machine let say M1 (client) to machine M2 (server) in the form of defined binary data set (Binary structure data which define for system to accept).

here my problem is I cannot execute my server script (which I have given above) on machine M2 (server) end. Is there any other way to pass data from M1 (client) to M2 (server) without executing server script


In reply to Perl Socket programming problem by sarf13

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.