girishatreya2005 has asked for the wisdom of the Perl Monks concerning the following question:
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");
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Starting a server on a machine whose IP is specified
by Corion (Patriarch) on Aug 21, 2010 at 08:40 UTC | |
|
Re: Starting a server on a machine whose IP is specified
by Crackers2 (Parson) on Aug 21, 2010 at 15:53 UTC |