IOS socket keeps background connection ios9.0 xcode8.0

Source: Internet
Author: User

This tutorial is based on the simple development of the Asyncsocket library!

The socket mechanism is not said today, after all, Baidu too much too detailed!

1. Start a new project;

2. To write the socket interface to follow the <</span>AsyncSocketDelegate> agent method;

Follow the Proxy method

3. Create a global service sending end;

Service side

? 4. Instantiate the server object in Viewdidload and bind the port number;

Service-Side strength approach

What to note here is: The port maximum is 65535 where the port is recommended to be set to more than 5000, there are some special ports, such as 8080 port for the video port, it is recommended not to occupy

5. How to implement Asyncsocket proxy method?:

Here you can create a variable array socketarray, which is used to save the access link, and keep the link;

1 for continuous monitoring, if set to 100, is not listening after 100 seconds;?

If you have a link, you'll go. This agent is used to receive messages sent by the new link

Note: The mechanism of iOS is to enter the background after the program will go into hibernation! This causes the socket to not communicate continuously, and then explains how to break it!

? 1. First: Join in plist

Voip

or configure as shown

?

Check the following two main check these two items will be able to maintain the socket connection

2. Then the proxy implementation method in the Appdelegate in the backend and back to the project

After entering the background and system borrowing time

?

Return the time after returning

Next write a timer here to realize the program in the background continue to work!

Timer

?

Once this is done, you can access it on the Web page: 127.0.0.1:5019 look at the console output ~?

Git:https://github.com/singletap?

IOS socket keeps background connection ios9.0 xcode8.0

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.