Hello wise ones,

I have written 2 perl scripts , one to start a server and the other to start a client . If I run these two scripts on different machines , they are able to communicate between themselves as desired.

However I want to write a program which forks off the server process and the client processes on machines whose IP addresses I pass as arguments. But that doesn't seem to be working . That is the server process fails with the error "bind: Cannot assign requested address ". Could someone let me know what I'm missing .

I'm suspecting this piece of code in the server script to be the culprit. But cant seem to put what is wrong here . I have tried with pack_sockaddr_in as well. It is also not working.

I'm including only that code which is giving me trouble . The code is failing with the error "bind: Cannot assign requested address" . If I run the same script on a machine whose IP is 10.72.206.79 . It runs fine without any issues.

#!/usr/bin/perl -w use strict; use Socket; #Subroutines sub usage () { die "usage: sock_server.pl [port]"; } #Declarations my $argc; my ($servaddr, $server_port, $server_ip, $server_name, $inaddr); my $nconns; my ($buf, $bufsize); my ($bytesread, $byteswritten, $totalwritten); my @hostentry ; #initializations $server_port = 12000; $nconns = 1; $bufsize = 1024; $buf = undef; $argc = @ARGV; if ($argc > 1) { usage(); } if ($argc == 1) { $server_port = $ARGV[0]; } $server_name = '10.72.206.79' ; @hostentry = gethostbyname($server_name); $server_ip = $hostentry[0]; $inaddr = inet_aton($server_ip) or die("inet_aton: $_\n"); $servaddr = pack_sockaddr_in($server_port, $inaddr); socket(SERVERSOCK, AF_INET, SOCK_STREAM, getprotobyname('tcp')) or die("socket: $!\n"); setsockopt(SERVERSOCK, SOL_SOCKET, SO_REUSEADDR, 1) or die("setsockopt: $!\n"); bind(SERVERSOCK, $servaddr) or die("bind: $!\n");

In reply to Starting a server on a machine whose IP is specified by girishatreya2005

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.