http://qs1969.pair.com?node_id=968453


in reply to Re: How to maintain a persistent connection over sockets?
in thread How to maintain a persistent connection over sockets?

BrowserUk,

I use IO::Socket::UNIX for both the client and server. The routines are almost exactly the same as the perl documentation: Note: I typed this code in, so I doubt it will compile and this is just part of a lot of other code.

Server:

use IO::Socket::UNIX; use strict; my $server = new IO::Socket::UNIX -> new ( Local => "$ROOT/envSocket +", Type => SOCK_STREAM, Reuse => 1, Listen => 147 ); [ ... error handling ... ] while ( 1 ) { my $client = $server => accept(); if ( defined $client ) { eval { while(<$client>) { $Todo .= $_; chomp($Todo); } } if ( $@ ) { ... } if ( $Todo ) { ... process work ... } close $client; } }

Client:

use IO::Socket::UNIX; use strict; my $server = new IO::Socket::UNIX -> new ( Peer => "$ROOT/envSocket +", Type => SOCK_STREAM, Timeout => 10 ); [ ... error handling ... ] print $server "$Todo\n"; shutdown ( $server, 1 ); while ( <$server> ) { $answer .= $_; } shutdown ( $server, 2 ); close $server; ... }

Even if I mistyped the code, the actual code works as expected. But the process is a lot slower than I had expected. Here are some results:

50,000 records processed: ( results are number/second ) 1 process | client/server Writes: 2,953 | 1,152 ReadNext: 35,138 | 2,870 ReadPrev: 34,236 | 2,616

So, if I could keep a persistent connection between the server and the client then performance may be better. Everything I have tried has just hung. Some information supplied by zentara has given me some new ideas.

Any help will be greatly appreciated.

Thank you

"Well done is better than well said." - Benjamin Franklin