Created
August 1, 2017 15:06
-
-
Save csujedihy/1fd6791fd37ca72bb895937fb2b70a8c to your computer and use it in GitHub Desktop.
EchoServer by SwfitDSSocket
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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