NWSocket 0.0.1

NWSocket 0.0.1

Maintained by Hoang Nguyen.

NWSocket 0.0.1

  • By
  • Hoang Nguyen


NWSocket is a Swift class that represents a socket connection conforming to the SocketInterface. It provides a convenient interface for managing socket connections, handling connection events, and performing read and write operations.


  • Connection Status: Track the current connection status with the isConnected property.
  • Delegate Pattern: Implement the SocketDelegate protocol to receive callbacks for various socket events.
  • Configurable: Customize the socket configuration, dispatch queues, and logging strategy.


Integration through CocoaPods

To integrate NetworkCompose into your Xcode project using CocoaPods, add the following to your Podfile:

pod 'NWSocket'

then run:

pod install

Integration through Swift Package Manager (SPM)

To integrate NetworkCompose using Swift Package Manager, add the following to your Package.swift file:

dependencies: [
    .package(url: "https://github.com/harryngict/NWSocket.git", from: "0.0.1")
targets: [
        name: "YourTargetName",
        dependencies: ["NWSocket"]

Replace "YourTargetName" with the name of your target. Then, run:

swift package update



final class ViewController: UIViewController {
    override func viewDidLoad() {
          let socket = Socket()
          socket.delegate = self
          do {
            try socket.connect(toHost: "your host", onPort: 1234)
          } catch {
            debugPrint("Error: \(error.localizedDescription)")

extension ViewController: SocketDelegate {
  func didReady(_ socket: SocketInterface, host: String, port: UInt16) {
    debugPrint("didReady: \(socket), host: \(host), port: \(port)")

  func didReceive(_ socket: SocketInterface, data: Data) {
    debugPrint("didReceive: \(socket), data: \(data)")

  func didDisconnect(_ socket: SocketInterface) {
    debugPrint("didDisconnect: \(socket)")


  func didConnect(_ socket: SocketInterface, 
                  withError error: Error?,
                  withTag: String) {
    debugPrint("didConnect: \(socket), error: \(String(describing: error)), withTag: \(withTag)")