iosswiftsocketsserversocketasyncsocket

Socket Response issue in iOS Socket Programming


I am developing app like Client/Driver.

In my application, We have used socket programming to track driver.

For tracking, Driver app will sent location(lat,lng) after every 5 seconds using socket and Client app will listen that socket response and update driver location.

This works fine, But my issue is :-

Sometimes client app get bad response as below :-

Socket Response

Means, bunch of responses in single socket response, and i can't handle this response.

Can anyone help me why i am getting this type of response, even i am sending single socket request every time from driver app at a time?

Hope for best.

Thank you.


Solution

  • Basically socket is used to broadcast data.

    This happened, because your old request is available on socket broadcast as it is, so client is getting multiple location. You have to ask your back end developer who has maintained socket, ask them to check if 109 id location is available then update that location and send 1 single on socket or delete previous one and send new one. So client will get only 1 location.

    Quick turn around you can do as set request time to 10 seconds instead of 5 seconds, each time when you want to send location. make connection to socket, send location and disconnect. Repeat this things at each time.

    Nothing seems wrong at iOS code side, mostly you have to maintain at back end side.

    You just need maintain proper architecture for this.