The purpose of the application is to listen to a specific UDP multicast, and then forward the data to any TCP clients connected to the server. The code works fine, but I have a problem with sockets that do not close after disconnecting TCP clients. The socketsniffer utility shows that sockets remain open and all UDP data continues to be redirected to clients. I believe the problem is with the if ($ write-> connected ()) block, as it always returns true, even if the TCP client is no longer connected. I use standard Windows Telnet to connect to the server and view data. When I close telnet, the TCP socket is supposed to close on the server.
Any reason why connected () shows connections are active, even if they are not? Also, what alternative should I use?
the code:
#!/usr/bin/perl use IO::Socket::Multicast; use IO::Socket; use IO::Select; my $tcp_port = "4550"; my $tcp_socket = IO::Socket::INET->new( Listen => SOMAXCONN, LocalAddr => '0.0.0.0', LocalPort => $tcp_port, Proto => 'tcp', ReuseAddr => 1, ); use Socket qw(IPPROTO_TCP TCP_NODELAY); setsockopt( $tcp_socket, IPPROTO_TCP, TCP_NODELAY, 1); use constant GROUP => '239.2.0.81'; use constant PORT => '6550'; my $udp_socket= IO::Socket::Multicast->new(Proto=>'udp',LocalPort=>PORT); $udp_socket->mcast_add(GROUP) || die "Couldn't set group: $!\n"; my $read_select = IO::Select->new(); my $write_select = IO::Select->new(); $read_select->add($tcp_socket); $read_select->add($udp_socket);
source share