TCPIP is a TCP/IP library for Swift 3.0.
- No
Foundation
dependency (Linux ready) - Local IP
- Remote IP
- TCP Server Socket
- TCP Client Socket
// 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 :(
}
// server
do {
let ip = try IP(port: 5555)
let serverSocket = try TCPServerSocket(ip: ip)
let clientSocket = try serverSocket.accept()
let yo = try clientSocket.receiveString(untilDelimiter: "\n")
} 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 :(
}
import PackageDescription
let package = Package(
dependencies: [
.Package(url: "https://github.com/Zewo/TCPIP.git", majorVersion: 0, minor: 4)
]
)
To use TCPIP in a command line application:
- Install the Swift Command Line Application Xcode template
Join us on Slack.
TCPIP is released under the MIT license. See LICENSE for details.