39 users online (1 members and 38 guests)  

Thread: chat


  Results 1 to 2 of 2

Related

  1. Best chat application for me    Forum: Internet Services
    Replies: 0
  2. 3d flash chat    Forum: Graphics Forum
    Replies: 5
  3. Help with chat    Forum: Javascript Forum
    Replies: 1
  4. Chat room    Forum: CGI Perl Forum
    Replies: 17
  1. #1
    sreenath's Avatar
    New User

    Status
    Offline
    Join Date
    Oct 2007
    Posts
    1

    chat

    The following is somethg like a chat program.

    use strict;
    use warnings;
    use threads;
    use IO::Socket::INET;
    my $port = 7745;
    my $thread1 = threads->create("client_thread");
    my $thread = threads->create("server_thread");
    #my $thread1 = threads->create("client_thread");
    sub server_thread {
    my %params = (
    LocalHost => '10.10.97.23',
    LocalPort => $port,
    Proto => 'tcp',
    Listen => 1,
    Reuse => 1,
    ReuseAddr => 1,
    );
    my $so = new IO::Socket::INET(%params);
    die "Server Socket Error: $!\n" unless $so;
    print STDERR "[Server Socket Connected]\n";
    my $client = $so->accept();
    $client->autoflush(1);
    while (1) {
    my $txt = <$client>;
    last unless defined($txt);
    chomp $txt;
    last if ($txt eq 'quit');
    print "server : $txt\n";
    }
    print "[Server finished]\n";
    }
    sub client_thread {
    sleep 1; # Give the server a head start
    my %params = (
    'PeerAddr' => '10.10.97.23',
    'PeerPort' => $port,
    'Proto' => 'tcp',
    'ReuseAddr' => 1,
    );
    my $so = new IO::Socket::INET(%params);
    print $so;
    $so->autoflush(1);
    die "Client Socket Error: $!\n" unless $so;
    print STDERR "[Client Socket Connected]\n";
    while (my $msg = <STDIN>) {
    chomp $msg;
    last if ($msg eq 'quit');
    print $so "$msg\n";
    }
    print "[Client finished]\n";
    }
    $thread->join();
    $thread1->join();

    When i am trying to connect to another system using its IP ,its showing some error.
    I am getting the o/p if i use the IP of my system.
    Expecting a reply as early as possible.

  2. #2
    xmassey's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Apr 2007
    Posts
    100

    Re: chat

    Have you checked through the documentation of the module(s) you are using to ensure you are writing the correct syntax/commands?



Tags for this Thread