Book Image

Swift Essentials

By : Alex Blewitt, Bandlem Limited
Book Image

Swift Essentials

By: Alex Blewitt, Bandlem Limited

Overview of this book

Table of Contents (16 chapters)
Swift Essentials
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Direct network connections


Although most application networking will involve downloading content over standard protocols such as HTTP(S) and using standard representations, there are times when having a specific data stream protocol is required. In this case, a stream oriented process will allow individual bytes to be read or written, or a datagram or packet oriented process can be used to send individual packets of data.

There are networking libraries to support both; an NSStream higher-level Objective-C based class provides the mechanism to drive stream-based responses, and although lower-level packet connections are possible with the CoreFoundation or the POSIX layer, local multiplayer gaming using the MultipeerConnectivity module is often appropriate.

Note

Local networking with the MultipeerConnectivity module involves creating an MCSession, followed by sendData to send NSData objects to connected peers and using the MCSessionDelegate to receiveData from connected peers. This is often...