Swiftpack.co - Package - PushpakN/-TCPIP

-TCPIP

Swift 5.1 version of code from https://github.com/ZewoGraveyard/TCPIP

Swift Platform License

TCPIP is a TCP/IP library for Swift 5.1.

Features

  • ☑ No Foundation dependency (Linux ready)
  • ☑ Local IP
  • ☑ Remote IP
  • ☑ TCP Server Socket
  • ☑ TCP Client Socket

Usage

import TCPIP

IP

// local
do {
    // all network interfaces
    let ip1 = try IP(port: 5555, mode: .IPV4)
    
    // specific network interface
    let ip2 = try IP(networkInterface: "en0", port: 5555, mode: .IPV6)
} catch {
    // something bad happened :(
}

// remote
do {
    let ip3 = try IP(address: "127.0.0.1", port: 5555, mode: .IPV4)
} catch {
    // something bad happened :(
}

TCP

// server
do {
    let ip = try IP(port: 6379) // Connecting to local IP.
    let serverSocket = try TCPServerSocket(ip: ip)
    let clientSocket = try serverSocket.accept()
    
    let clientMessage = try clientSocket?.receiveString(untilDelimiter: "\n")
    print("Client Message - \(clientMessage ?? "")")
} catch {
    // something bad happened :(
}

// client
do {
    let ip = try IP(address: "127.0.0.1", port: 5555)
    let clientSocket = try TCPClientSocket(ip: ip)
    
    // calls to send append the data to an internal
    // buffer to minimize system calls
    try clientSocket.sendString("yo\n")
    // flush actually sends all data in the buffer
    try clientSocket.flush()
} catch {
    // something bad happened :(
}

Package

import PackageDescription

let package = Package(
    dependencies: [
        .Package(url: "https://github.com/PushpakN/-TCPIP.git")
    ]
)

Command Line Application

To use TCPIP in a command line application:

License

TCPIP is released under the MIT license. See LICENSE for details.

Github

link
Stars: 0

Dependencies

Used By

Total: 0

Releases

Initial Version - 2020-02-06 05:04:00