sven has asked for the wisdom of the Perl Monks concerning the following question:
after having searched the web for hours, trying to find an existing solution to my problem, I am now requesting your help.
Problem:
I am currently (trying) to write a client-server pair, that will be used to edit a file on a remote computer.
Because I can't be sure that either machine is constantly available, I want to monitor the server-client constantly. If the connection drops, a reconnect is initiated. I.e. I have the client constantly running, and only start the server app, when I need to change something.
After connecting, the communication starts from the server-side by requesting the current content of the file. That way I could easily (sort of) implement the monitoring of the client-side connection:
If the client can't read from the socket any longer, it is asumed, that the connection is broken. I close the socket and reopen a new one. Works fine.sub ReadData{ my $recv_data; my $send_data; my $command; my $working_data; while ($endEx eq "false"){ if ($connected eq "true") { $socket->recv($recv_data,1024); if ($recv_data ne "") { # make sure, we can read from the + socket, if ($debug_log eq "on") { &WriteLog("Message received: $recv_data"); } $command = substr($recv_data , 0 , 3); if ($command eq "GET"){ $send_data = "OLD:" . &GetCurrent; } elsif ($command eq "PUT"){ $working_data = substr($recv_data , 4); &SetNew($working_data); $send_data = "NEW:" . &GetCurrent; } #elsif ($command eq "SET"){ #will be used in t +he future for setting startstop handling #} if ($command eq "GET" || $command eq "PUT"){ $socket->send($send_data); if ($debug_log eq "on") { &WriteLog("Message sent: $send_data"); } } } else{ $connected = "false"; # if not, reset socket an +d reconnect Win32::GUI::NotifyIcon::Change( $ni, -icon => $icon_no, -tip => "connecting...", ); } usleep($reconnecttime); } else { &WriteLog("Connection lost"); close $socket; $socket=""; &ConnectServer(); } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: TCP server, that realizes connection loss
by mykl (Monk) on Jul 14, 2009 at 14:52 UTC | |
|
Re: TCP server, that realizes connection loss
by jethro (Monsignor) on Jul 14, 2009 at 14:10 UTC | |
|
Re: TCP server, that realizes connection loss
by Anonymous Monk on Jul 14, 2009 at 19:33 UTC | |
by sven (Initiate) on Jul 15, 2009 at 12:44 UTC | |
|
Re: TCP server, that realizes connection loss
by sven (Initiate) on Sep 02, 2009 at 08:42 UTC |