Skip to content

ZewoGraveyard/TCPIP

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

[Deprecated] TCPIP

Swift Platform License Slack

TCPIP is a TCP/IP library for Swift 3.0.

Features

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

Usage

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: 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 :(
}

Package

import PackageDescription

let package = Package(
    dependencies: [
        .Package(url: "https://github.com/Zewo/TCPIP.git", majorVersion: 0, minor: 4)
    ]
)

Command Line Application

To use TCPIP in a command line application:

Community

Slack

Join us on Slack.

License

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