Last active
July 15, 2017 05:12
-
-
Save ArchieR7/bb609ab6e0a44283de93a0852c8febb1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import CocoaAsyncSocket | |
let socket = GCDAsyncSocket(delegate: <#T##GCDAsyncSocketDelegate?#>, delegateQueue: <#T##DispatchQueue?#>) | |
do { | |
try socket.connect(toHost: Host, onPort: Port) | |
} catch { | |
print(error) | |
} | |
// GCDAsyncSocketDelegate | |
func socket(_ sock: GCDAsyncSocket, didConnectToHost host: String, port: UInt16) { | |
// 連接上後,需要執行 readData 等候 Server 執行 writeData 的動作 | |
sock.readData(withTimeout: -1, tag: 0) | |
} | |
func socket(_ sock: GCDAsyncSocket, didRead data: Data, withTag tag: Int) { | |
// 讀完資料後,還是需要再執行一次 readData,來等候下一次的資料傳輸過來 | |
sock.readData(withTimeout: -1, tag: 0) | |
} | |
func socketDidDisconnect(_ sock: GCDAsyncSocket, withError err: Error?) { | |
} | |
func socket(_ sock: GCDAsyncSocket, didWriteDataWithTag tag: Int) { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment