ios tcp socket操作问题
伊谢尔伦
伊谢尔伦 2017-04-18 09:36:27
0
2
330
伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(2)
小葫芦

First of all, let me declare that I cannot answer your question. If you are working on the Internet, you should know that a simple question of why -1 is returned may not be a good question.

Secondly, I’ll try to answer your other questions and share my personal views by the way.

When I first joined a startup company making social apps in the Nth year, I used POSIX and supported iOS3.1.3~iOS4 systems. Our manager asked me to change IM on both iOS and Android. There were many problems with disconnection, retraining, freezing, memory, and threads... In order to be cross-platform, I chose POSIX development as my first choice, but many problems arose in the process, and the information was lost. I often work overtime at night to communicate and learn from the server. The set of server code was accumulated after five or six years of tens of millions of online tests. But I still didn’t stick to it, and finally chose CFNetwork. Later, there were several bugs due to iOS upgrades, and then I have been using GCDAsyncSocket until now. Later, we also developed audio and video protocols, clients built their own servers, etc., but none of them used POSIX.

In fact, I just want to say that you should think carefully about why you should use POSIX, cross-platform? Custom protocol? If not, it is strongly recommended to choose a more advanced API or use a mature third-party library.

POSIX under iOS has always had a lot of pitfalls. It requires sufficient experience, familiarity with Apple's documentation, and the need to keep up with system updates and complete testing. Because choosing POSIX means handling IP by yourself, supporting IPv4/IPv6/IPv6-only, handling Wifi/WWAN switching, IP reachability, VPN, thread safety, memory, various network anomalies, some magical network "suspended deaths", etc. Wait... iOS will make https mandatory next year, and you have to update accordingly.

It is necessary to read Apple’s official network programming documentation once or twice. As for the socket library you want, I saw several porting projects a long time ago that support iOS. They may not be maintained now. I have forgotten the name. You can search it on open source code hosting websites and Google groups. I just recently tested something and played segmentfault for a few days. According to my current observation, you can’t find the answers to the questions you will encounter now and in the future here, and you may not be able to find them on stackoverflow. The way to learn and solve problems is to look at other people's code. Apple's open source code is a treasure.

Maybe I’m being serious, or maybe the function you want is not as complicated as I thought. Again, unless you have to cross-platform or implement a custom protocol, and you have enough time to fill in the pits, then keep playing. POSIX, otherwise use advanced API or third-party library.

Friendly reminder: cherish life.

Ty80

After

write returns -1, please use errnoto get the error code

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!