Hi Folks,
Whenever I try to make the connection I got the following message :
[connection] nw_socket_handle_socket_event [C1:1] Socket SO_ERROR [61: Connection refused]
2022-09-20 12:26:27.695439+0530 NetworkSample[6165:1970925] [connection] nw_read_request_report [C1] Receive failed with error "Connection refused"
2022-09-20 12:26:27.711315+0530 NetworkSample[6165:1970930] did receive, error: POSIXErrorCode(rawValue: 61): Connection refused
2022-09-20 12:26:27.711474+0530 NetworkSample[6165:1970930] did stop
2022-09-20 12:26:32.685079+0530 NetworkSample[6165:1970930] is waiting: POSIXErrorCode(rawValue: 61): Connection refused
2022-09-20 12:26:37.971629+0530 NetworkSample[6165:1970930] was cancelled
2022-09-20 12:26:39.410259+0530 NetworkSample[6165:1970930] did stop
2022-09-20 12:26:39.410312+0530 NetworkSample[6165:1970926] [connection] [C1 192.168.1.17:8080 tcp, attribution: developer] is already cancelled, ignoring cancel
I am using that code snippets
class Main {
init(hostName: String, port: Int) {
let host = NWEndpoint.Host(hostName)
let port = NWEndpoint.Port("\(port)")!
self.connection = NWConnection(host: host, port: port, using: .tcp)
}
let connection: NWConnection
func start() {
NSLog("will start")
self.connection.stateUpdateHandler = self.didChange(state:)
self.startReceive()
self.connection.start(queue: .main)
}
func stop() {
self.connection.cancel()
NSLog("did stop")
}
private func didChange(state: NWConnection.State) {
switch state {
case .setup:
break
case .waiting(let error):
NSLog("is waiting: %@", "\(error)")
case .preparing:
break
case .ready:
break
case .failed(let error):
NSLog("did fail, error: %@", "\(error)")
self.stop()
case .cancelled:
NSLog("was cancelled")
self.stop()
@unknown default:
break
}
}
private func startReceive() {
self.connection.receive(minimumIncompleteLength: 1, maximumLength: 65536) { data, _, isDone, error in
if let data = data, !data.isEmpty {
NSLog("did receive, data: %@", data as NSData)
}
if let error = error {
NSLog("did receive, error: %@", "\(error)")
self.stop()
return
}
if isDone {
NSLog("did receive, EOF")
self.stop()
return
}
self.startReceive()
}
}
func send(line: String) {
let data = Data("\(line)\r\n".utf8)
self.connection.send(content: data, completion: NWConnection.SendCompletion.contentProcessed { error in
if let error = error {
NSLog("did send, error: %@", "\(error)")
self.stop()
} else {
NSLog("did send, data: %@", data as NSData)
}
})
}
static func run() -> Never {
let m = Main(hostName: "192.168.1.17", port: 8080)
m.start()
let t = DispatchSource.makeTimerSource(queue: .main)
var counter = 99
t.setEventHandler {
m.send(line: "\(counter) bottles of beer on the wall.")
counter -= 1
if counter == 0 {
m.stop()
exit(EXIT_SUCCESS)
}
}
t.schedule(wallDeadline: .now() + 1.0, repeating: 1.0)
t.activate()
dispatchMain()
}
}
Post
Replies
Boosts
Views
Activity
Hi Carlddy
Please remove UIView allocation from TableFooterView and TableHeaderView in UITableView appearance methods
This issue has been resolved by commenting the following code :
UITableView *tableView = [UITableView appearance];
[tableView setSectionIndexColor:[UIColor grayColor]];
if ([[UITableView class ] instancesRespondToSelector:@selector(setSectionIndexBackgroundColor:)]) {
[tableView setSectionIndexBackgroundColor:[UIColor clearColor]];
}
[tableView setTableFooterView:[UIView new]];
[tableView setTableHeaderView:[UIView new]];
I know this is strange, But it solved in my case.
Any Update on above reported issue (Ticket No : FB8256200).