From 58f4f59cafd82f78e70499925287da41e5ef013e Mon Sep 17 00:00:00 2001 From: Orkhan Alikhanov Date: Fri, 15 Dec 2017 17:17:41 +0400 Subject: [PATCH] Updated readme --- README.md | 36 ++++++++++++++++++++++++------------ Socket.swift.podspec | 2 +- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 2b08667..e1845e0 100644 --- a/README.md +++ b/README.md @@ -7,25 +7,37 @@ A POSIX socket wrapper written in swift. -## OS +## Features -Works in linux, iOS, macOS and tvOS +- TLS support +- Linux, iOS, macOS and tvOS support +- Clean and understanable code + + +If you consider something needs to be implemented, just [open an issue](issues/new) or make a PR + ## Example ```swift -let server = try Socket.tcpListening(port: 8090) //start socket listening at localhost:8090 +let server = try Socket(.inet, type: .stream, protocol: .tcp) // create server socket +try server.set(option: .reuseAddress, true) // set SO_REUSEADDR to 1 +try server.bind(port: 8090, address: nil) // bind 'localhost:8090' address to the socket +try server.listen() // allow incoming connections -let client = try Socket(.inet, type: .stream, protocol: .tcp) -try client.connect(port: 8090) //connecting to the socket at localhost:8090 -let clientAtServerside = try server.accept() +let client = try Socket(.inet, type: .stream, protocol: .tcp) // create client socket +try client.connect(port: 8090) // connect to localhost:8090 -let bytes = ([UInt8])("Hello World".utf8) -try clientAtServerside.write(bytes) //sening bytes to the client socket +let clientAtServerside = try server.accept() // accept client connection + +let helloBytes = ([UInt8])("Hello World".utf8) +try clientAtServerside.write(helloBytes) // sending bytes to the client clientAtServerside.close() -while let byte = try? client.read() { //reading bytes sent by server socket - print(byte) -} +var buffer = [UInt8](repeating: 0, count: helloBytes.count) // allocate buffer +let numberOfReadBytes = try client.read(&buffer, size: helloBytes.count) +print(numberOfReadBytes == helloBytes.count) // true +print(buffer == helloBytes) // true + client.close() server.close() ``` @@ -45,7 +57,7 @@ To integrate Socket.swift into your Xcode project using CocoaPods, specify it in ```ruby source 'https://github.com/CocoaPods/Specs.git' target '' do - pod 'Socket.swift', '~> 2.0' + pod 'Socket.swift', '~> 2.1' end ``` diff --git a/Socket.swift.podspec b/Socket.swift.podspec index 1b36311..94d6a3e 100644 --- a/Socket.swift.podspec +++ b/Socket.swift.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'Socket.swift' - s.version = '2.0.0' + s.version = '2.1.0' s.summary = 'A POSIX socket wrapper written in swift.' s.homepage = 'https://github.com/BiAtoms/Socket.swift' s.license = { :type => 'MIT', :file => 'LICENSE' }