It's a simple socket server.
If I remove Socket
class and put serverSocket
variable and startSocketServer
function inside the ViewController
class Socket server will be started to listening.
I check by lsof -i :6000
command to determine if socket started to listening or not.
Whats wrong?!
import UIKit
import CocoaAsyncSocket
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let server = Socket()
server.startSocketServer()
}
}
class Socket: NSObject, GCDAsyncSocketDelegate {
var serverSocket = GCDAsyncSocket()
/// Staring socket server
func startSocketServer() {
self.serverSocket = GCDAsyncSocket(delegate: self, delegateQueue: dispatch_get_main_queue())
do {
try serverSocket.acceptOnInterface(nil, port: 6000)
} catch {
print("Port access failed")
}
}
}
--
You received this message because you are subscribed to the Google Groups "CocoaAsyncSocket" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cocoaasyncsock...@googlegroups.com.
To post to this group, send email to cocoaasy...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cocoaasyncsocket/fda27c7f-1463-4a1e-84e3-043aa7d077a7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
class ViewController: UIViewController {
let server = Socket()
override func viewDidLoad() {
super.viewDidLoad()
server.startSocketServer()
}
}