converting from Objective-C to Swift

I have a TCP app running that was written in Objective-C on iOS 10.3.3 on ipads. We have over a hundred, so upgrading them is not an option. I need to update the app to Swift. I am having an issue finding equivalent code for my communications. In O-C I have:

socketQueue = dispatch_queue_create("socketQueue", NULL);

listenSocket = ([GCDAsyncSocket alloc] initWIthDelegate:self delegateQueue:socketQueue];

[self startTCPListener]

////// startTCPListener ///////

int port = xxxx;

NSError * error - nil;

if (![listenSocket acceptOnPort:port error:&error]) {

// error }

Can someone please give me an example that is Swift-compliant and also on iOS 10.3.3 (cannot use await/async)? Thank you, jerry

NWConnection which seems to be for TCP and other lower level protocols, but seems to be iOS 12+ only.

One possibility is to use...

		tcpStreamTask = URLSession.shared.streamTask(withHostName: host, port: port)
		tcpStreamTask?.resume()
		while running {
			let result = try await tcpStreamTask?.readData(ofMinLength: 10, maxLength: 8096, timeout: 0)
...
		let toSend = dataString.data(using: .utf8)!
		try await tcpStreamTask?.write(toSend, timeout: 0)
...

...the URLSessionStreamTask, the example above is with async code but can do with closures too. If that is something you can do.

converting from Objective-C to Swift
 
 
Q