How to handle a TCP connection in background? for Poker app server-client app

纵然是瞬间 提交于 2019-12-08 03:28:00

问题


I am working on Poker app based on server-client based app. When Poker App goes to the background after some time TCP/IP connection lost because app unable to send/recieve any packet to/from the server. Sever ends socket connection. how can i able to establish connection for long time and update my game UI


回答1:


The topic you asked for, is called "Background Execution".

First:

You can't update the UI while the app enters the background. But you will be able to finish your API-Requests to the server and save the data on phone while using beginBackgroundTaskWithExpirationHandler. You can use this method to write a block which communicates to your server and handles all the data your app will receive. If the App enters the foreground again, you can use this data received in background to update your UI then.

It is important, that those background tasks have to finish in a short time, so it will be not a good idea here to have an infinite loop. Otherwise, iOS will terminate your process. How much time you really get after your app gets backgrounded is determined by iOS.

Second:

If you want to keep tcp/ip-connections always on even if the app remains in the background, Apple provides a very powerful background mode which enables you to run code for any time in the background. It's called VoIP-Services. Unfortunately your app should provide some VoIP-Stuff to not being rejected by Apple. Here is a good article about those services.



来源:https://stackoverflow.com/questions/30680975/how-to-handle-a-tcp-connection-in-background-for-poker-app-server-client-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!