TCP-Client receiving error

  1. vor 2 Monaten

    Hey!

    I tried programming simple TCP-Clients using SwiftSocket and CocoaAsyncSocket. Both are connecting to the server, and both are sending messages, but neither SwiftSocket nor CocoaAsyncSocket are able to receive messages. Xcode just prints out "-1" after connecting to the server. As a Server I tried several Socket-Test Applications and a simple Echo-Server running on an Arduino.

    My Code for SwiftSocket looks like this :

    let client = TCPClient(address: "192.168.178.23", port: 8000)
            switch client.connect(timeout: 1) {
            case .success:
                
                switch client.send(string: "hey" ) {
                case .success:
                    guard let data = client.read(1024*10) else { return }
                    
                    if let response = String(bytes: data, encoding: .utf8) {
                        print(response)
                    }
                case .failure(let error):
                    print(error)
                }
     
                
                guard let data = client.read(1024*10) else { return }
                
                if let response = String(bytes: data, encoding: .utf8) {
                    print(response)
                }
                
                
            case .failure(let error):
                print(error)
            }
     

    (It's just the example from the Github side)

    Do I have a general Problem with my Network setup (since Both Libraries have the same error) or am I missing something else?

    I hope you can help me with that!

 

oder registriere Dich, um zu antworten!