Overview of the API
func toBytes() -> [UInt8] {
// convert something to bytes ...
}
let socket = UDPConnect()
socket.connect(host: "1.2.3.4", port: 9000)
let msg: [UInt8] = toBytes()
socket.send(msg)
let msg2: String = "Hello" // unicode only, no emoji
socket.send(msg2)
let conn: NWConnection = getConnection()
let socket = UDPConnect(connection: conn)
let ip = getIPAddress()
let server = UDPBind()
server.bind(host: ip, port: 9500)
struct Bob {
let a: Double
let b: Int16
// convert this struct into an array of bytes for transmission
// across the network
func pack() -> [UInt8] {
var buffer: [UInt8] = []
buffer.append(0xfe) // header byte
buffer.append(contentsOf: toByteArray(self.a))
buffer.append(contentsOf: toByteArray(self.b))
print("buffer size: \(buffer.count)")
return buffer
}
}