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(); } } }
In reply to TCP server, that realizes connection loss by sven
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |