Just reviewed some code on this forum and I couldn’t find example where reconnection could take place.
I am using WIP lib to connect to server over gprs connection.
My modem has to be all time connected and in case of connection drop I need to reestablish connection.
Where is proper place to establish connection to server?
Firstly, you can’t connect to a “server” using a GPRS connection. The GPRS bearer connection is the data connection the the cellular network. You need another protocol to actually create the connection to the server. The most common options are:
TCP :create a TCP server on the server, and a TCP client on the device
UDP: A connectionless, un-guaranteed protocol that requires a UDP listener on the server side
If you want the connection to be permanently established, the best way is to periodically communicate with the server and make sure you get the correct response. If the communications fail, or if you receive any error events in your TCP handlers, you can shut down the connection and recreate it.
Thanks tomridl for answer , I forgot to mention that I am making TCP client connection to server over GPRS data.
For recreating connection to TCP server in case of conntion drop, is it fine if I place function startClient(); in WIP_CEV_PEER_CLOSE and IP_CEV_ERROR block?
see code below:
Another thing for keeping connection alive, shouldn’t I set WIP_COPT_KEEPALIVE in order to maintain connection all the time?
Instead of periodically commincating to server?
WIP_COPT_KEEPALIVE - “Sends a NOOP command every n tenth of seconds, so that the server and any NAT on the way won’t shut down the connection”
Hello,
I think you should check the error type(ev->content.error.errnum) in WIP_CEV_ERROR case to decide creating the socket again. The error type may not be related with socket disconnection. In this case you dont need to create a new socket.
And you can handle WIP_CEV_DONE event also just in case of your application closes the socket somehow.
WIP_COPT_KEEPALIVE option will work for your case of keeping the connection alive. But you can also implement your own method so that you can have control on that methot.