i am using a Raspberry Pi (with Codesys 220.127.116.11) as a TCP IP server and almost 80 Raspberry Pi (with Codesys 18.104.22.168) as TCP IP clients. I make an Array of 80 NBS.Connections and let the clients make connections. The server allocates one element of the aforesaid Array randomly. The whole communication is working.
i have following questions:
1. The client makes connection then on server side the Server/NBS.connection.Active[x] goes true but it stays true even if the client goes physically offline. Is it so or i made an error? right now i send the timestamp from client to server and as long as it is changing, i know the connection is ok, else i reconnect. Is there any elegent way to solve this.
2. Can i decide from server side that Server/NBS.connection.Active[x] is only for Client IP xxx.xxx.xxx.xxx
3. How can i decide from client side that the server Offline is?
any help is appreciated!
Thanks in advance
Probably the easiest approach to this is to implement a heartbeat.
In each client/server function block, have a boolean input called hearbeat_check from an external timer TON that runs every X+1 seconds... or have a dedicated TON for each function block, but that would be a waste of space. Anyway, for each function block have two bytes: one called current and the other called missed_heartbeat. This variable current is set to 1 if TCP receive buffer has new message. On the rising edge of hearbeat_check, increment missed_heartbeat if current is equal to 0. Else, reset missed_heartbeat to 0. If missed_heartbeat exceeds some Y value, then close connection.
Log in to post a comment.