Skip to content

Instantly share code, notes, and snippets.

@csujedihy
Created August 1, 2017 15:06
Show Gist options
  • Save csujedihy/1fd6791fd37ca72bb895937fb2b70a8c to your computer and use it in GitHub Desktop.
Save csujedihy/1fd6791fd37ca72bb895937fb2b70a8c to your computer and use it in GitHub Desktop.
EchoServer by SwfitDSSocket
import Cocoa
import SwiftDSSocket
class ViewController: NSViewController {
var client: SwiftDSSocket?
var server: SwiftDSSocket?
let ServerTag = 0
override func viewDidLoad() {
super.viewDidLoad()
server = SwiftDSSocket(delegate: self, delegateQueue: .main, type: .tcp)
try? server?.accept(onPort: 9999)
}
}
extension ViewController: SwiftDSSocketDelegate {
func socket(sock: SwiftDSSocket, didAcceptNewSocket newSocket: SwiftDSSocket) {
newSocket.readData(tag: ServerTag)
}
func socket(sock: SwiftDSSocket, didRead data: Data, tag: Int) {
sock.write(data: data, tag: ServerTag)
sock.readData(tag: ServerTag)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment