Hello all...
I have a little situation here I thought some of you might be able to shed some light on. I have a socket server/client combo running. The server I wrote myself, but the client is someone else's. (That may be important, I dunno). Here is the basic problem:
Both are designed to be run in the field, using the Internet as a method of connecting, so in order to simulate various problems, we have been fooling around with a couple of ways to disrupt the connection to see if the server will detect that, and cycle itself. (Which is what it's designed to do).
For the first test, we start a batch send on the client, let it begin, and yank the network cable.
Everything's fine. The server discards the incomplete message (if any), and cycles itself. Plugging the cable back in has the desired effect of the client continuing where it left off. All fine and dandy.
For the second test, we start the batch send, and Ctrl-C the client program. The server again registers the disconnect, and cycles itself. The problem starts when we then restart the client. The client comes up and says it makes a successful connection, and begins sending data again. The server, however, never registers a connect at all. It just sits listening. Since the client waits for an ACK message from the server between each message it sends, it gets stuck waiting for an ACK on a message that according to the server, never got there in the first place. The server never sends a NACK because it never even registers the connection attempt.
I am really unfamiliar with sockets under win32 anyway, and it's been a while since programming them on *nix.
Any thoughts? Ideas? Suggestions?
Here's the code where it's stopping (and the surrounding code):
while(1) {
my @ready = ();
while(@ready = $sel->can_read(0)) {
debug_out("while \$sel->can_read(1)") if $debug > 99;
my ($new);
foreach $client (@ready) {
debug_out("foreach \$client") if $debug > 99;
if($client == $server) {
debug_out("client == server") if $debug > 99;
$new = $server->accept();
$sel->add($new);
} else {
debug_out("client != server") if $debug > 99;
$remote_ip = whos_there($client);
debug_out("got remote IP") if $debug > 99;
serv_out("Connect from $remote_ip");
$msg_total = 0;
debug_out("reset msg total") if $debug > 99;
while(<$client>) {
debug_out("while <\$client>") if $debug > 99;
$message = $_;
debug_out("msg = '$message'") if $debug > 99;
raw_out($message) if($config{'rawout'} == 1);
# for logging:
my $msg_length = length($message);
debug_out("main: msg_length = $msg_length") if $de
+bug > 5;
next if $msg_length < 4;
$msg_total++;
debug_out("main: incr msg total to $msg_total") if
+ $debug > 99;
serv_out("Processing $msg_length bytes from $remot
+e_ip\n");
# split the message into segments
# we are splitting on carriage returns (NOT newli
+ne!)
@segments = split /\015/, $message;
debug_out("main: split msg into segments") if $deb
+ug > 99;
# call a sub to loop over the segments
process_segment(\@segments, $message, $client);
debug_out("main: process segment returns") if $deb
+ug > 99;
debug_out("main: refreshing logs") if $debug > 99;
refresh_logs();
} # end while(<$client>);
serv_out("Closing connection from $remote_ip");
}
$sel->remove($client);
debug_out("Client removed") if $debug > 99;
$client->close();
debug_out("Client closed") if $debug > 99;
$server = create_socket($config{'port'});
debug_out("server cycled") if $debug > 99;
}
}
}
The create_socket routine prints a message about succesfully creating the listen socket, and returns, that's where we appear to be stopping...(I'm getting the "server cycled" message.)
Anything would be much appreciated.
-HaB
hword.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.