A simple and easy TCP Client in Swift.
let tcp = EasyTCP(hostName: "tcpbin.com", port: 4242)
tcp.start()let result = try await tcp.send("Hello")
// Convert to String
let resultString = String(data: result, encoding: .utf8)!
print(resultString)let tcp = EasyTCP(hostName: "tcpbin.com", port: 4243, using: .tls)If you're using a JSON RPC, you can specify the last letter which will be send from the Server.
let tcp = EasyTCP(hostName: "tcpbin.com", port: 4242, lastLetters: "}", debug: true)When you are using the JSON RCP, you can send and recieve objects. You have to specify the type that confirms to codable.
struct Item: Codable {
let a: String
}
let result = try await tcp.sendJsonRpc(input: Item(a: "Hello"), output: Item.self)If you recieve huge data packages the client will wait until all data packages arrive. If you have a slow connection please set the waitTime higher:
let tcp = EasyTCP(hostName: "tcpbin.com", port: 4242, waitTime: 0.7)You dont have to do this if you are using the JSON-RPC.