Swift 4如何在字符串前附加4个字节?

时间:2018-09-06 18:15:29

标签: swift socket.io tcpclient

现在,发送消息且我的代码在以下时,ios端this中的服务器输出:

let client = TCPClient(address: "172.20.10.4", port: 1333)

switch client.connect(timeout: 20) {
case .success:
    print("Connected to Server")

    let string = "GETNEWGAMEBOOKING"
    //   let data =  Array(string.utf8)
    let data = string.data(using: .utf8)!
    switch client.send(data: data){
    case .success:
        guard let data = client.read(1024*10) else { return }
        print(data)
        let strResponse = String(data: Data(data), encoding: .utf8)
        print(strResponse!)
        if let response = String(bytes: data, encoding: .utf8) {
            print(response)
        }
        break;
    case .failure(let err):
        print(err.localizedDescription)
        break;
    }
case .failure(let error):
    print(error)
}
  • 我的问题是在android输出上如何在消息中添加这4个字节?

  • 我正在为此项目使用“ SwiftSocket”。

0 个答案:

没有答案