58 users online (0 members and 58 guests)  


  Results 1 to 5 of 5

Related

  1. Simple tree    Forum: Javascript Forum
    Replies: 7
  2. simple xml problem    Forum: PHP Forum
    Replies: 2
  3. Keep It Simple S****d    Forum: HTML Forum
    Replies: 3
  4. My simple art site...    Forum: Show it off!
    Replies: 7
  1. #1
    tommyyang's Avatar
    New User

    Status
    Offline
    Join Date
    Mar 2005
    Posts
    3

    BUG in a simple IO::Socket Program

    I know it is a little out of the topic of the forum,but I guess
    your guys here could easily solve this problem.

    I wrote a simple TCP client using IO::Socket.But this program
    can only hear from the server,it can not send out a single bit.
    Whenever I tried to input the messages that supposed to be sent to the server, the program will get stuck,I have checked the code for hundreds of times, but I really don't know what's wrong with it.

    in other words, when I try to "print $socket $_.CRLF;", the program does not print the "$_.CRLF" to "$socket",it stocks it
    in the system input buffer and does not send it out, set
    $socket->autoflush(1), the problem remains!
    Somebody help me!

    I am using WinXP SP1,ActivePerl 5.8.6

    here is my code:

    #!/usr/bin/perl
    #file gap.pl
    #usage gap.pl [host] [port]
    #Forking TCP network client

    use strict;
    use IO::Socket qw(EFAULT :crlf);

    my $host = shift or die "Usage : gap.pl host [port]\n";
    my $port = shift || 'echo';

    my $socket = IO::Socket::INET->new("$host:$port") or die $@;

    my $child = fork();
    die "can't fork : $!" unless defined $child;

    if ($child) {
    $SIG{CHLD} = sub {exit 0};
    user_to_host($socket);
    $socket->shutdown(1);
    sleep;
    }
    else {
    host_to_user($socket);
    warn "connection closed by freign host. \n";
    }

    sub user_to_host {
    my $s = shift;
    while (<>) {
    chomp;
    print $s $_.CRLF;
    }
    }

    sub host_to_user {
    my $s = shift;
    $/ = CRLF;
    while (<$s>) {
    chomp;
    print $_."\n";
    }
    }

  2. #2
    QuietDean's Avatar
    Administrator

    Status
    Offline
    Join Date
    Oct 2000
    Location
    Bournemouth, UK
    Posts
    2,662
    Hi, welcome to the forum.

    As soon as you mentioned XP, I just had to check: "Is Perl.exe an allowed program in your firewall? either XP's built-in one, or another one?"
    If one of our members helps you, please click the icon to add to their reputation!
    No support via email or private message - use the forums!
    Before you ask, have you Searched?

  3. #3
    tommyyang's Avatar
    New User

    Status
    Offline
    Join Date
    Mar 2005
    Posts
    3
    I have disabled XP's built-in firewall, and there is no other firewalls on my computer.

  4. #4
    QuietDean's Avatar
    Administrator

    Status
    Offline
    Join Date
    Oct 2000
    Location
    Bournemouth, UK
    Posts
    2,662
    I was reading about someone else with a similar problem. It turned out to be sending of blank lines.

    They had a workaround, read thru this but I think the part you need is at the end: http://www.issociate.de/board/post/142639/Fork_/_Socket.html
    If one of our members helps you, please click the icon to add to their reputation!
    No support via email or private message - use the forums!
    Before you ask, have you Searched?

  5. #5
    tommyyang's Avatar
    New User

    Status
    Offline
    Join Date
    Mar 2005
    Posts
    3
    I have tried this:
    changing "#!/usr/bin/perl" to #!perl -w --"

    but,the problem remains! Oh,I am entering the crazy mode too.....waawawaawwa&)(*&&(*&(*



Tags for this Thread