swiftsocket / SwiftSocket

The easy way to use sockets on Apple platforms
BSD 3-Clause "New" or "Revised" License
1.68k stars 402 forks source link

Base46 can't be send #165

Open fleetour opened 5 years ago

fleetour commented 5 years ago

Hallo Iam have the problem, that i can't send long String through Swiftsocket. the short ones arrive ! The Code iam using as following :

this is the method to send any thing to the HOST , as iam using the Mobil as Client :

func ConnectionAufbau(trans_Nachricht:String, istFoto: Bool ) {

    let lastCharc = Character(UnicodeScalar(03))

    let Port = self.getPort() // Aus standard auslesen ?
    let IP_Adresse = self.getIPAdresse() //getIPAdresse()
    let client = TCPClient(address: IP_Adresse, port: Port)
    switch client.connect(timeout: 10){
    case .success:
        self.connected = true
        self.pollForResponse(for: client)
        print("verbunden")
        self.delegate.IsConnected (isConnected : true)

        print("Nachricht ist" ,trans_Nachricht)

        switch client.send(string: "\(trans_Nachricht)\(lastCharc)" ) {
        case .success:
          //  print("Succ)
            if istFoto == true {
                DispatchQueue.main.async {
                self.delegate.FotoGesendet(isConnected: true, istGesendet: true, Fehler: "kein")
                }
            }
            print("gesendet")
            guard let data = client.read(1024*10) else { return }

            if let response = String(bytes: data, encoding: .utf8) {
                print(response)
            }
        case .failure(let error as NSError):
            if istFoto == true {
                self.delegate.FotoGesendet(isConnected: true, istGesendet: false, Fehler: "unbekannte Fehler")

            }
            print("Error ist ", error)
        }
    case .failure(let error):
        if istFoto == true {
            self.delegate.FotoGesendet(isConnected: false, istGesendet: false, Fehler: error as! String)

        }
        print(error)

    }

}

Can any body help ? or Should i use another Library ?