UDP Client/Server Questions 
Author Message
 UDP Client/Server Questions

All - I'm using ActivePerl under Win2k.  I wrote a small client and
server using IO::Socket::INET.

Problem is that I can't seem to shut the server down cleanly if the
client goes down first.  If the server is shut down first, I catch the
Ctrl-C, break out of the while loop, close the socket, and clean up a
log file that I'm writing.

If the client goes down first, I can't seem to catch the Ctrl-C in the
server, the server goes down, and I don't get to close a log file that
I'm writing.

I've registered a sig handler using sigtrap:
use sigtrap qw(handler my_handler normal-signals error-signals);

while ($quit == 0) {
     next unless $sock->recv($msg_in,MAX_MSG_LEN);
     print "$msg_in\n";

Quote:
}

# Close log file and other things happen here.

sub my_handler {
  ++$quit;

Quote:
}

Any suggestions?  If this is a Win2k/signal issue, any suggestions on
getting around it?

Thanks for the help,
Mark



Mon, 17 May 2004 03:47:02 GMT  
 UDP Client/Server Questions

Quote:
> All - I'm using ActivePerl under Win2k.  I wrote a small client and
> server using IO::Socket::INET.
(snip)
> If the client goes down first, I can't seem to catch the Ctrl-C in the
> server, the server goes down, and I don't get to close a log file that
> I'm writing.

(snip)

> while ($quit == 0) {
>      next unless $sock->recv($msg_in,MAX_MSG_LEN);
>      print "$msg_in\n";
> }

Not sure why it would crash, but this did hang on me; we can't check $quit
until recv comes back, and the only client is already finished.

As far as the that goes, you could poll--

my $sel  = new IO::Select;
my $time = 1;

$sel->add($sock);

while ($quit == 0) {
    if ($sel->can_read($time)) {
        $sock->recv($msg_in,MAX_MSG_LEN);
        print "$msg_in\n";
    }

Quote:
}

If you don't want to touch the socket in your signal handler.

hth
-Steve



Mon, 17 May 2004 07:52:21 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Wanted: UDP client/server example

2. UDP based client-server perl scripts

3. Wanted: example of UDP client/server

4. UDP Client/Server Tutorial

5. Win32: UDP Client/Server Socket Problem under NT4

6. server to client using udp

7. Server/Server & Client/Server

8. VMS Perl Question: Client/Server under UCX 1.3?

9. Client/Server Question

10. Client/Server question

11. tcp client/server question...

12. Client-server sockets question.

 

 
Powered by phpBB® Forum Software