Client and server

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Javagopal
    New Member
    • Aug 2013
    • 3

    #1

    Client and server

    I have written simple client and server program.Its work on same machine not work on different machine . what i do?
    please tell me
  • hosting charges
    New Member
    • Aug 2013
    • 10

    #2
    May be due to firewall/anti virus restriction.

    Comment

    • numberwhun
      Recognized Expert Moderator Specialist
      • May 2007
      • 3467

      #3
      You need to give us more details on what the "simple" client and server program is doing for its connectivity, functionality, etc. We know nothing about it and without more information, we can only theorize about possibilities. If you give us more info (or even share the code), then maybe we can provide more definitive avenues for investigation. Also, knowing what OS's your attempting to run it on would also be helpful.

      Regards,

      Jeff

      Comment

      • Javagopal
        New Member
        • Aug 2013
        • 3

        #4
        ok.Thanks for your solution.how to solve firewall/anti virus restriction.ple ase sent me solution

        Comment

        • buy domain
          New Member
          • Aug 2013
          • 6

          #5
          Are you getting errors like, "Could not open socket" from your client and server program? if yes, just use a 5 digit port.

          Comment

          • Javagopal
            New Member
            • Aug 2013
            • 3

            #6
            The below code are my program
            Code:
            #Client program
            #!/usr/bin/perl
            use IO::Socket::INET;
            use strict;
            
            
            my $name = '24.221.34.34'; #Server IP
            my $port = '78901';
            
            my $socket = IO::Socket::INET->new('PeerAddr' => $name,
                                               'PeerPort' => $port,
                                            'Proto' => 'tcp') or die "Can't create socket ($!)\n";
            
            print "Client sending\n";
            while (1) {
                my $msg = <STDIN>;
                print $socket $msg;
                print scalar <$socket>;
            }
            close $socket
                or die "Can't close socket ($!)\n";
            #Server program 
            
            
            #!/usr/bin/perl
            use IO::Socket::INET;
            use strict;
            
            my $port = "78901";
            
            my $socket = IO::Socket::INET->new('LocalPort' => $port,
                                               'Proto' => 'tcp',
                                               'Listen' => SOMAXCONN)
                or die "Can't create socket ($!)\n";
            	print "Socket connection";
            
            
            while (my $client = $socket->accept) {
                my $name = gethostbyaddr($client->peeraddr, AF_INET);
                my $port = $client->peerport;
                while (<$client>) {
                    print "[$name $port] $_";
                    my @out = `$_`;
                    print @out;
                    print $client "$.: @out";
                }
                close $client
                    or die "Can't close ($!)\n";
            }
            
            die "Can't accept socket ($!)\n";
            The client program have displayed below error
            Can't create socket (No connection could be made because the target machine actvely refused it.)
            please help me

            Comment

            • numberwhun
              Recognized Expert Moderator Specialist
              • May 2007
              • 3467

              #7
              First, you need to have the shebang line ( #!/usr/bin/perl) as the very first line in your script. If you put it anywhere BUT the first line, it is a comment and doesn't do anything.

              Second, your issue, from reading the error, is on the second machine, which "actively refused it". I would start by troubleshooting why it refused the connection.

              Another thing you can do is try printing "$!" as part of your die() function call as it prints the last error received.

              Regards,

              Jeff

              Comment

              Working...