This is a note to communicate with UDP in Swift.
I installed SwiftSocket via cocoapods and wrote it like this. I used it to communicate with the WOOM-02.
This file contains 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 UIKit | |
import SwiftSocket | |
class ViewController: UIViewController { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
let client = UDPClient(address: "192.168.43.76", port: 12345) | |
let data: Data = "kabigon-daisuiki".data(using: .utf8)! | |
let result = client.send(data: data) | |
print(result) | |
} | |
} |