Socket Problem...

From: Hobbit HK (hobbit_hk_at_hotmail.com)
Date: 11/27/03


Date: 27 Nov 2003 04:14:03 -0800

I'm using AtivePerl 5.8 on WinXP and trying to do a script which
listens and writes to the same socket (with fork of course...). Now,
everything works great until I'm trying to write to the socket... The
program just stucks, I think because I'm trying to read and write
simultaneously... If I comment the read part everything goes smooth
(except I can't get msgs :)), here's the code:

use IO::Socket;
$|=1;
($host, $port) = @ARGV;
$port=23 if !$port;
$sock=new IO::Socket::INET->new(PeerAddr=>$host, PeerPort=>$port,
Proto=>'tcp') or die "Can't connect to $host on port $port! $!\n";
$sock->autoflush(1);
print "[Connected to $host on port $port]\n";
die "Can't fork! $!\n" unless defined($kidpid=fork());
if ($kidpid) {
    while (sysread($sock, $byte, 1)==1) {
        print "$byte";
    }
    kill 9, $kidpid;
}
else {
    while (defined($msg=<STDIN>)) {
        print "$msg\n";
    }
}



Relevant Pages

  • Re: How to close a blocked socket
    ... I have an server application that listens to a port. ... I use a thread to run the socket part, so I don't block the user ... If I close the application, and open again, the port is still in use. ...
    (microsoft.public.dotnet.languages.csharp)
  • Unbinding sockets in threads..
    ... listens on that port for data I'm sending it and puts ... and I can't find any way of unbinding the port. ... If I try it not in a thread the del function works fine (i.e. creating and ... binding a socket s and then deleting it) Can anyone suggest some ...
    (comp.lang.python)
  • Re: how to write a program (not a webpage) in php?
    ... program, but written in php. ... I'd like that this program listens on a port to recive a message: ... Ewoud pointed you to the socket interface; it's as simple as opening a socket, listening for a message, and once received, close the socket. ...
    (comp.lang.php)
  • Re: How to close a blocked socket
    ... I have an server application that listens to a port. ... I use a thread to run the socket part, so I don't block the user interface. ... If I close the application, and open again, the port is still in use. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Problem with socket
    ... Be aware that those port numbers are part of the IANA-assigned range. ... socket operations on sockets for which there are no handles... ... The result of using comma lists is ... you have used the completely meaningless word "crash" to describe your ...
    (microsoft.public.vc.mfc)