Hi,
I am trying to implement SSL socket connection with an android device. I am able to receive the message from android device successfully.
But while trying to write data , issue happens.
This is my write function
func write(message: String) { let data = message.data(using: .utf8)! data.withUnsafeBytes { guard let pointer = $0.baseAddress?.assumingMemoryBound(to: UInt8.self) else { print("Error") return } self.outputStream?.write(pointer, maxLength: data.count) } }
If I send a small string, it is not received at android end. But when I send a large string, say count 30000 char. It will be received at android side. But first two characters will be lost.
Below is my connect function:
var inputStream: InputStream? var outputStream: OutputStream? var inputDelegate: StreamDelegate? var outputDelegate: StreamDelegate? func connect(host: String, port: Int) { Stream.getStreamsToHost(withName:host, port: 8443, inputStream: &inputStream, outputStream: &outputStream) inputDelegate = self outputDelegate = self inputStream!.delegate = inputDelegate outputStream!.delegate = outputDelegate inputStream!.schedule(in:RunLoop.main, forMode: .default) outputStream!.schedule(in:RunLoop.main, forMode: .default) inputStream!.setProperty(kCFStreamSocketSecurityLevelNegotiatedSSL, forKey: Stream.PropertyKey.socketSecurityLevelKey) outputStream!.setProperty(kCFStreamSocketSecurityLevelNegotiatedSSL, forKey: Stream.PropertyKey.socketSecurityLevelKey) let sslSettings : [NSString: Any] = [ NSString(format: kCFStreamSSLValidatesCertificateChain): kCFBooleanFalse, NSString(format: kCFStreamSSLPeerName): kCFNull, NSString(format: kCFStreamSSLIsServer): kCFBooleanFalse ] inputStream!.setProperty(sslSettings, forKey: kCFStreamPropertySSLSettings as Stream.PropertyKey) outputStream!.setProperty(sslSettings, forKey: kCFStreamPropertySSLSettings as Stream.PropertyKey) inputStream!.open() outputStream!.open() }
Please help to debug the issue.