diff --git a/.gitignore b/.gitignore
index a916178..41aaaa1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,10 +1,4 @@
-*.xcuserdatad
-*.DS_Store
-*.pbxproj
-*.xcuserstate
-*.xccheckout
# Xcode
-.DS_Store
build/
*.pbxuser
!default.pbxuser
@@ -14,12 +8,36 @@ build/
!default.mode2v3
*.perspectivev3
!default.perspectivev3
-*.xcworkspace
-!default.xcworkspace
xcuserdata
-profile
+*.xccheckout
*.moved-aside
DerivedData
-.idea/
-# Pods - for those of you who use CocoaPods
-Pods
+*.hmap
+*.ipa
+*.xcuserstate
+
+#OS X Stuff
+.localized
+.DS_Store
+*.zip
+
+# Pods
+Pods/
+
+# Editors
+.idea
+*.swp
+
+# Fastlane
+fastlane/report.xml
+*.mobileprovision
+*.certSigningRequest
+*.cer
+
+# Keys
+*.pem
+*.pkey
+*.p12
+
+# Rbenv
+.ruby-version
diff --git a/.swift-version b/.swift-version
new file mode 100644
index 0000000..9f55b2c
--- /dev/null
+++ b/.swift-version
@@ -0,0 +1 @@
+3.0
diff --git a/README.md b/README.md
index ba60363..4388952 100644
--- a/README.md
+++ b/README.md
@@ -1,104 +1,91 @@
-# a simple socket library for apple swift lang
-# usage
-> drag ysocket.c and ysocket.swift to your project
-> just use apis in YSocket class
+# SwiftSocket
+SwiftSocket library provides as easy to use interface for socket based connections on server or client side. Supports both TCP and UDP sockets.
-# api usage
-## create client socket
-``` swift
-//create a socket connect to www.apple.com and port at 80
-var client:TCPClient = TCPClient(addr: "www.apple.com", port: 80)
-```
-## connect with timeout
-``` swift
-var (success, errmsg) = client.connect(timeout: 10)
+# Installation
+## Cocoapods
+Add this to your `Podfile`:
+```ruby
+pod 'SwiftSocket'
```
+And run then `pod install`
-## send data
-``` swift
-var (success, errmsg) = client.send(str:"GET / HTTP/1.0\n\n")
-//or you can send binnary data
-//socket.send(data:[Int8])
-```
+# Code examples
-## read data
+## Create client socket
``` swift
-var data = client.read(1024*10) //return optional [Int8]
+// Create a socket connect to www.apple.com and port at 80
+let client = TCPClient(address: "www.apple.com", port: 80)
```
-
-## close socket
+## Connect with timeout
+You can also set timeout to `-1` or leave parameters empty (`client.connect()`) to turn off connection timeout.
``` swift
-var (success, errormsg) = client.close()
+ switch client.connect(timeout: 10) {
+ case .success:
+ // Connection successful 🎉
+ case .failure(let error):
+ // 💩
+ }
```
-## create servert socket
-
+## Send data
``` swift
-var server:TCPServer = TCPServer(addr: "127.0.0.1", port: 8080)
+let data: Data = // ... Bytes you want to send
+let result = client.send(data: data)
```
-## listen
-
+## Read data
``` swift
-var (success, msg) = server.listen()
+var data = client.read(1024*10) //return optional [Int8]
```
-### accept
+
+## Close socket
``` swift
-var client = server.accept() //now you can use client socket api to read and write
+client.close()
```
-# client socket example
+## Client socket example
``` swift
-//创建socket
-var client:TCPClient = TCPClient(addr: "www.apple.com", port: 80)
-//连接
-var (success, errmsg) = client.connect(timeout: 1)
-if success {
- //发送数据
- var (success, errmsg) = client.send(str:"GET / HTTP/1.0\n\n" )
- if success {
- //读取数据
- var data = client.read(1024*10)
- if let d = data {
- if let str = String.stringWithBytes(d, length: d.count, encoding: NSUTF8StringEncoding){
- println(str)
- }
+let client = TCPClient(address: "www.apple.com", port: 80)
+switch client.connect(timeout: 1) {
+ case .success:
+ switch client.send(string: "GET / HTTP/1.0\n\n" ) {
+ case .success:
+ guard let data = client.read(1024*10) else { return }
+
+ if let response = String(bytes: data, encoding: .utf8) {
+ print(response)
}
- }else {
- println(errmsg)
+ case .failure(let error):
+ print(error)
}
-} else {
- println(errmsg)
+ case .failure(let error):
+ print(error)
}
+
```
-# server socket example (echo server)
+## Server socket example (echo server)
``` swift
-func echoService(client c:TCPClient) {
- println("newclient from:\(c.addr)[\(c.port)]")
+func echoService(client: TCPClient) {
+ print("Newclient from:\(c.address)[\(c.port)]")
var d = c.read(1024*10)
c.send(data: d!)
c.close()
}
-func testserver(){
- var server:TCPServer = TCPServer(addr: "127.0.0.1", port: 8080)
- var (success, msg) = server.listen()
- if success {
+
+func testServer() {
+ let server = TCPServer(address: "127.0.0.1", port: 8080)
+ switch server.listen() {
+ case .success:
while true {
if var client = server.accept() {
echoService(client: client)
} else {
- println("accept error")
+ print("accept error")
}
}
- } else {
- println(msg)
+ case .failure(let error):
+ print(error)
}
}
```
-
-# Copyright and License
-Code released under the BSD license.
-
-# QQ group
-275935304
diff --git a/ysocket-ios/Info.plist b/Sources/Info.plist
similarity index 90%
rename from ysocket-ios/Info.plist
rename to Sources/Info.plist
index d3de8ee..d63d290 100644
--- a/ysocket-ios/Info.plist
+++ b/Sources/Info.plist
@@ -15,9 +15,7 @@
CFBundlePackageType
FMWK
CFBundleShortVersionString
- 1.0
- CFBundleSignature
- ????
+ 1.1
CFBundleVersion
$(CURRENT_PROJECT_VERSION)
NSPrincipalClass
diff --git a/Sources/Result.swift b/Sources/Result.swift
new file mode 100644
index 0000000..880a287
--- /dev/null
+++ b/Sources/Result.swift
@@ -0,0 +1,28 @@
+import Foundation
+
+public enum Result {
+ case success
+ case failure(Error)
+
+ public var isSuccess: Bool {
+ switch self {
+ case .success:
+ return true
+ case .failure:
+ return false
+ }
+ }
+
+ public var isFailure: Bool {
+ return !isSuccess
+ }
+
+ public var error: Error? {
+ switch self {
+ case .success:
+ return nil
+ case .failure(let error):
+ return error
+ }
+ }
+}
diff --git a/Sources/Socket.swift b/Sources/Socket.swift
new file mode 100644
index 0000000..043566b
--- /dev/null
+++ b/Sources/Socket.swift
@@ -0,0 +1,53 @@
+//
+// Copyright (c) <2014>, skysent
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+// 1. Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// 2. Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the distribution.
+// 3. All advertising materials mentioning features or use of this software
+// must display the following acknowledgement:
+// This product includes software developed by skysent.
+// 4. Neither the name of the skysent nor the
+// names of its contributors may be used to endorse or promote products
+// derived from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY skysent ''AS IS'' AND ANY
+// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL skysent BE LIABLE FOR ANY
+// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+
+import Foundation
+
+public typealias Byte = UInt8
+
+open class Socket {
+
+ public let address: String
+ public let port: Int32
+ public var fd: Int32?
+
+ public init(address: String, port: Int32) {
+ self.address = address
+ self.port = port
+ }
+
+}
+
+public enum SocketError: Error {
+ case queryFailed
+ case connectionClosed
+ case connectionTimeout
+ case unknownError
+}
diff --git a/Sources/SwiftSocket.h b/Sources/SwiftSocket.h
new file mode 100644
index 0000000..fff7aba
--- /dev/null
+++ b/Sources/SwiftSocket.h
@@ -0,0 +1,9 @@
+#import
+
+//! Project version number for SwiftSocket
+FOUNDATION_EXPORT double SwiftSocketVersionNumber;
+
+//! Project version string for SwiftSocket
+FOUNDATION_EXPORT const unsigned char SwiftSocketVersionString[];
+
+// In this header, you should import all the public headers of your framework using statements like #import
diff --git a/Sources/TCPClient.swift b/Sources/TCPClient.swift
new file mode 100644
index 0000000..04c5b8f
--- /dev/null
+++ b/Sources/TCPClient.swift
@@ -0,0 +1,174 @@
+//
+// Copyright (c) <2014>, skysent
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+// 1. Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// 2. Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the distribution.
+// 3. All advertising materials mentioning features or use of this software
+// must display the following acknowledgement:
+// This product includes software developed by skysent.
+// 4. Neither the name of the skysent nor the
+// names of its contributors may be used to endorse or promote products
+// derived from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY skysent ''AS IS'' AND ANY
+// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL skysent BE LIABLE FOR ANY
+// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+
+import Foundation
+
+@_silgen_name("ytcpsocket_connect") private func c_ytcpsocket_connect(_ host:UnsafePointer,port:Int32,timeout:Int32) -> Int32
+@_silgen_name("ytcpsocket_close") private func c_ytcpsocket_close(_ fd:Int32) -> Int32
+@_silgen_name("ytcpsocket_send") private func c_ytcpsocket_send(_ fd:Int32,buff:UnsafePointer,len:Int32) -> Int32
+@_silgen_name("ytcpsocket_pull") private func c_ytcpsocket_pull(_ fd:Int32,buff:UnsafePointer,len:Int32,timeout:Int32) -> Int32
+@_silgen_name("ytcpsocket_listen") private func c_ytcpsocket_listen(_ address:UnsafePointer,port:Int32)->Int32
+@_silgen_name("ytcpsocket_accept") private func c_ytcpsocket_accept(_ onsocketfd:Int32,ip:UnsafePointer,port:UnsafePointer) -> Int32
+
+open class TCPClient: Socket {
+
+ /*
+ * connect to server
+ * return success or fail with message
+ */
+ open func connect(timeout: Int) -> Result {
+ let rs: Int32 = c_ytcpsocket_connect(self.address, port: Int32(self.port), timeout: Int32(timeout))
+ if rs > 0 {
+ self.fd = rs
+ return .success
+ } else {
+ switch rs {
+ case -1:
+ return .failure(SocketError.queryFailed)
+ case -2:
+ return .failure(SocketError.connectionClosed)
+ case -3:
+ return .failure(SocketError.connectionTimeout)
+ default:
+ return .failure(SocketError.unknownError)
+ }
+ }
+ }
+
+ /*
+ * close socket
+ * return success or fail with message
+ */
+ open func close() {
+ guard let fd = self.fd else { return }
+
+ _ = c_ytcpsocket_close(fd)
+ self.fd = nil
+ }
+
+ /*
+ * send data
+ * return success or fail with message
+ */
+ open func send(data: [Byte]) -> Result {
+ guard let fd = self.fd else { return .failure(SocketError.connectionClosed) }
+
+ let sendsize: Int32 = c_ytcpsocket_send(fd, buff: data, len: Int32(data.count))
+ if Int(sendsize) == data.count {
+ return .success
+ } else {
+ return .failure(SocketError.unknownError)
+ }
+ }
+
+ /*
+ * send string
+ * return success or fail with message
+ */
+ open func send(string: String) -> Result {
+ guard let fd = self.fd else { return .failure(SocketError.connectionClosed) }
+
+ let sendsize = c_ytcpsocket_send(fd, buff: string, len: Int32(strlen(string)))
+ if sendsize == Int32(strlen(string)) {
+ return .success
+ } else {
+ return .failure(SocketError.unknownError)
+ }
+ }
+
+ /*
+ *
+ * send nsdata
+ */
+ open func send(data: Data) -> Result {
+ guard let fd = self.fd else { return .failure(SocketError.connectionClosed) }
+
+ var buff = [Byte](repeating: 0x0,count: data.count)
+ (data as NSData).getBytes(&buff, length: data.count)
+ let sendsize = c_ytcpsocket_send(fd, buff: buff, len: Int32(data.count))
+ if sendsize == Int32(data.count) {
+ return .success
+ } else {
+ return .failure(SocketError.unknownError)
+ }
+ }
+
+ /*
+ * read data with expect length
+ * return success or fail with message
+ */
+ open func read(_ expectlen:Int, timeout:Int = -1) -> [Byte]? {
+ guard let fd:Int32 = self.fd else { return nil }
+
+ var buff = [Byte](repeating: 0x0,count: expectlen)
+ let readLen = c_ytcpsocket_pull(fd, buff: &buff, len: Int32(expectlen), timeout: Int32(timeout))
+ if readLen <= 0 { return nil }
+ let rs = buff[0...Int(readLen-1)]
+ let data: [Byte] = Array(rs)
+
+ return data
+ }
+}
+
+open class TCPServer: Socket {
+
+ open func listen() -> Result {
+ let fd = c_ytcpsocket_listen(self.address, port: Int32(self.port))
+ if fd > 0 {
+ self.fd = fd
+ return .success
+ } else {
+ return .failure(SocketError.unknownError)
+ }
+ }
+
+ open func accept() -> TCPClient? {
+ guard let serferfd = self.fd else { return nil }
+
+ var buff: [Int8] = [Int8](repeating: 0x0,count: 16)
+ var port: Int32 = 0
+ let clientfd: Int32 = c_ytcpsocket_accept(serferfd, ip: &buff, port: &port)
+
+ guard clientfd >= 0 else { return nil }
+ guard let address = String(cString: buff, encoding: String.Encoding.utf8) else { return nil }
+
+ let client = TCPClient(address: address, port: port)
+ client.fd = clientfd
+
+ return client
+ }
+
+ open func close() {
+ guard let fd: Int32=self.fd else { return }
+
+ _ = c_ytcpsocket_close(fd)
+ self.fd = nil
+ }
+}
diff --git a/Sources/UDPClient.swift b/Sources/UDPClient.swift
new file mode 100644
index 0000000..c671d44
--- /dev/null
+++ b/Sources/UDPClient.swift
@@ -0,0 +1,165 @@
+//
+// Copyright (c) <2014>, skysent
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+// 1. Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// 2. Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the distribution.
+// 3. All advertising materials mentioning features or use of this software
+// must display the following acknowledgement:
+// This product includes software developed by skysent.
+// 4. Neither the name of the skysent nor the
+// names of its contributors may be used to endorse or promote products
+// derived from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY skysent ''AS IS'' AND ANY
+// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL skysent BE LIABLE FOR ANY
+// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+
+import Foundation
+
+@_silgen_name("yudpsocket_server") func c_yudpsocket_server(_ host:UnsafePointer,port:Int32) -> Int32
+@_silgen_name("yudpsocket_recive") func c_yudpsocket_recive(_ fd:Int32,buff:UnsafePointer,len:Int32,ip:UnsafePointer,port:UnsafePointer) -> Int32
+@_silgen_name("yudpsocket_close") func c_yudpsocket_close(_ fd:Int32) -> Int32
+@_silgen_name("yudpsocket_client") func c_yudpsocket_client() -> Int32
+@_silgen_name("yudpsocket_get_server_ip") func c_yudpsocket_get_server_ip(_ host:UnsafePointer,ip:UnsafePointer) -> Int32
+@_silgen_name("yudpsocket_sentto") func c_yudpsocket_sentto(_ fd:Int32,buff:UnsafePointer,len:Int32,ip:UnsafePointer,port:Int32) -> Int32
+@_silgen_name("enable_broadcast") func c_enable_broadcast(_ fd:Int32)
+
+open class UDPClient: Socket {
+ public override init(address: String, port: Int32) {
+ let remoteipbuff: [Int8] = [Int8](repeating: 0x0,count: 16)
+ let ret = c_yudpsocket_get_server_ip(address, ip: remoteipbuff)
+ guard let ip = String(cString: remoteipbuff, encoding: String.Encoding.utf8), ret == 0 else {
+ super.init(address: "", port: 0) //TODO: change to init?
+ return
+ }
+
+ super.init(address: ip, port: port)
+
+ let fd: Int32 = c_yudpsocket_client()
+ if fd > 0 {
+ self.fd = fd
+ }
+ }
+
+ /*
+ * send data
+ * return success or fail with message
+ */
+ open func send(data: [Byte]) -> Result {
+ guard let fd = self.fd else { return .failure(SocketError.connectionClosed) }
+
+ let sendsize: Int32 = c_yudpsocket_sentto(fd, buff: data, len: Int32(data.count), ip: self.address, port: Int32(self.port))
+ if Int(sendsize) == data.count {
+ return .success
+ } else {
+ return .failure(SocketError.unknownError)
+ }
+ }
+
+ /*
+ * send string
+ * return success or fail with message
+ */
+ open func send(string: String) -> Result {
+ guard let fd = self.fd else { return .failure(SocketError.connectionClosed) }
+
+ let sendsize = c_yudpsocket_sentto(fd, buff: string, len: Int32(strlen(string)), ip: address, port: port)
+ if sendsize == Int32(strlen(string)) {
+ return .success
+ } else {
+ return .failure(SocketError.unknownError)
+ }
+ }
+
+ /*
+ * enableBroadcast
+ */
+ open func enableBroadcast() {
+ guard let fd: Int32 = self.fd else { return }
+
+ c_enable_broadcast(fd)
+ }
+
+ /*
+ *
+ * send nsdata
+ */
+ open func send(data: Data) -> Result {
+ guard let fd = self.fd else { return .failure(SocketError.connectionClosed) }
+
+ var buff = [Byte](repeating: 0x0,count: data.count)
+ (data as NSData).getBytes(&buff, length: data.count)
+ let sendsize = c_yudpsocket_sentto(fd, buff: buff, len: Int32(data.count), ip: address, port: port)
+ if sendsize == Int32(data.count) {
+ return .success
+ } else {
+ return .failure(SocketError.unknownError)
+ }
+ }
+
+ open func close() {
+ guard let fd = self.fd else { return }
+
+ _ = c_yudpsocket_close(fd)
+ self.fd = nil
+ }
+ //TODO add multycast and boardcast
+}
+
+open class UDPServer: Socket {
+
+ public override init(address: String, port: Int32) {
+ super.init(address: address, port: port)
+
+ let fd = c_yudpsocket_server(address, port: port)
+ if fd > 0 {
+ self.fd = fd
+ }
+ }
+
+ //TODO add multycast and boardcast
+ open func recv(_ expectlen: Int) -> ([Byte]?, String, Int) {
+ if let fd = self.fd {
+ var buff: [Byte] = [Byte](repeating: 0x0,count: expectlen)
+ var remoteipbuff: [Int8] = [Int8](repeating: 0x0,count: 16)
+ var remoteport: Int32 = 0
+ let readLen: Int32 = c_yudpsocket_recive(fd, buff: buff, len: Int32(expectlen), ip: &remoteipbuff, port: &remoteport)
+ let port: Int = Int(remoteport)
+ var address = ""
+ if let ip = String(cString: remoteipbuff, encoding: String.Encoding.utf8) {
+ address = ip
+ }
+
+ if readLen <= 0 {
+ return (nil, address, port)
+ }
+
+ let rs = buff[0...Int(readLen-1)]
+ let data: [Byte] = Array(rs)
+ return (data, address, port)
+ }
+
+ return (nil, "no ip", 0)
+ }
+
+ open func close() {
+ guard let fd = self.fd else { return }
+
+ _ = c_yudpsocket_close(fd)
+ self.fd = nil
+ }
+}
diff --git a/Sources/ytcpsocket.c b/Sources/ytcpsocket.c
new file mode 100644
index 0000000..68bd7b9
--- /dev/null
+++ b/Sources/ytcpsocket.c
@@ -0,0 +1,175 @@
+//
+// Copyright (c) <2014>, skysent
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+// 1. Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// 2. Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the distribution.
+// 3. All advertising materials mentioning features or use of this software
+// must display the following acknowledgement:
+// This product includes software developed by skysent.
+// 4. Neither the name of the skysent nor the
+// names of its contributors may be used to endorse or promote products
+// derived from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY skysent ''AS IS'' AND ANY
+// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL skysent BE LIABLE FOR ANY
+// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+void ytcpsocket_set_block(int socket, int on) {
+ int flags;
+ flags = fcntl(socket, F_GETFL, 0);
+ if (on == 0) {
+ fcntl(socket, F_SETFL, flags | O_NONBLOCK);
+ } else {
+ flags &= ~ O_NONBLOCK;
+ fcntl(socket, F_SETFL, flags);
+ }
+}
+
+int ytcpsocket_connect(const char *host, int port, int timeout) {
+ struct sockaddr_in sa;
+ struct hostent *hp;
+ int sockfd = -1;
+ hp = gethostbyname(host);
+ if (hp == NULL) {
+ return -1;
+ }
+
+ bcopy((char *)hp->h_addr, (char *)&sa.sin_addr, hp->h_length);
+ sa.sin_family = hp->h_addrtype;
+ sa.sin_port = htons(port);
+ sockfd = socket(hp->h_addrtype, SOCK_STREAM, 0);
+ ytcpsocket_set_block(sockfd,0);
+ connect(sockfd, (struct sockaddr *)&sa, sizeof(sa));
+ fd_set fdwrite;
+ struct timeval tvSelect;
+ FD_ZERO(&fdwrite);
+ FD_SET(sockfd, &fdwrite);
+ tvSelect.tv_sec = timeout;
+ tvSelect.tv_usec = 0;
+
+ int retval = select(sockfd + 1, NULL, &fdwrite, NULL, &tvSelect);
+ if (retval < 0) {
+ close(sockfd);
+ return -2;
+ } else if(retval == 0) {//timeout
+ close(sockfd);
+ return -3;
+ } else {
+ int error = 0;
+ int errlen = sizeof(error);
+ getsockopt(sockfd, SOL_SOCKET, SO_ERROR, &error, (socklen_t *)&errlen);
+ if (error != 0) {
+ close(sockfd);
+ return -4;//connect fail
+ }
+
+ ytcpsocket_set_block(sockfd, 1);
+ int set = 1;
+ setsockopt(sockfd, SOL_SOCKET, SO_NOSIGPIPE, (void *)&set, sizeof(int));
+ return sockfd;
+ }
+}
+
+int ytcpsocket_close(int socketfd){
+ return close(socketfd);
+}
+
+int ytcpsocket_pull(int socketfd, char *data, int len, int timeout_sec) {
+ if (timeout_sec > 0) {
+ fd_set fdset;
+ struct timeval timeout;
+ timeout.tv_usec = 0;
+ timeout.tv_sec = timeout_sec;
+ FD_ZERO(&fdset);
+ FD_SET(socketfd, &fdset);
+ int ret = select(socketfd + 1, &fdset, NULL, NULL, &timeout);
+ if (ret <= 0) {
+ return ret; // select-call failed or timeout occurred (before anything was sent)
+ }
+ }
+ int readlen = (int)read(socketfd, data, len);
+ return readlen;
+}
+
+int ytcpsocket_send(int socketfd, const char *data, int len){
+ int byteswrite = 0;
+ while (len - byteswrite > 0) {
+ int writelen = (int)write(socketfd, data + byteswrite, len - byteswrite);
+ if (writelen < 0) {
+ return -1;
+ }
+ byteswrite += writelen;
+ }
+ return byteswrite;
+}
+
+//return socket fd
+int ytcpsocket_listen(const char *address, int port) {
+ //create socket
+ int socketfd = socket(AF_INET, SOCK_STREAM, 0);
+ int reuseon = 1;
+ setsockopt(socketfd, SOL_SOCKET, SO_REUSEADDR, &reuseon, sizeof(reuseon));
+
+ //bind
+ struct sockaddr_in serv_addr;
+ memset( &serv_addr, '\0', sizeof(serv_addr));
+ serv_addr.sin_family = AF_INET;
+ serv_addr.sin_addr.s_addr = inet_addr(address);
+ serv_addr.sin_port = htons(port);
+ int r = bind(socketfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr));
+ if (r == 0) {
+ if (listen(socketfd, 128) == 0) {
+ return socketfd;
+ } else {
+ return -2;//listen error
+ }
+ } else {
+ return -1;//bind error
+ }
+}
+
+//return client socket fd
+int ytcpsocket_accept(int onsocketfd, char *remoteip, int *remoteport) {
+ socklen_t clilen;
+ struct sockaddr_in cli_addr;
+ clilen = sizeof(cli_addr);
+ int newsockfd = accept(onsocketfd, (struct sockaddr *) &cli_addr, &clilen);
+ char *clientip=inet_ntoa(cli_addr.sin_addr);
+ memcpy(remoteip, clientip, strlen(clientip));
+ *remoteport = cli_addr.sin_port;
+ if (newsockfd > 0) {
+ return newsockfd;
+ } else {
+ return -1;
+ }
+}
diff --git a/Sources/yudpsocket.c b/Sources/yudpsocket.c
new file mode 100644
index 0000000..de6d002
--- /dev/null
+++ b/Sources/yudpsocket.c
@@ -0,0 +1,135 @@
+//
+// Copyright (c) <2014>, skysent
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+// 1. Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// 2. Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the distribution.
+// 3. All advertising materials mentioning features or use of this software
+// must display the following acknowledgement:
+// This product includes software developed by skysent.
+// 4. Neither the name of the skysent nor the
+// names of its contributors may be used to endorse or promote products
+// derived from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY skysent ''AS IS'' AND ANY
+// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL skysent BE LIABLE FOR ANY
+// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#define yudpsocket_buff_len 8192
+
+//return socket fd
+int yudpsocket_server(const char *address, int port) {
+
+ //create socket
+ int socketfd=socket(AF_INET, SOCK_DGRAM, 0);
+ int reuseon = 1;
+ int r = -1;
+
+ //bind
+ struct sockaddr_in serv_addr;
+ serv_addr.sin_len = sizeof(struct sockaddr_in);
+ serv_addr.sin_family = AF_INET;
+ if (address == NULL || strlen(address) == 0 || strcmp(address, "255.255.255.255") == 0) {
+ r = setsockopt(socketfd, SOL_SOCKET, SO_BROADCAST, &reuseon, sizeof(reuseon));
+ serv_addr.sin_port = htons(port);
+ serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
+ } else {
+ r = setsockopt(socketfd, SOL_SOCKET, SO_REUSEADDR, &reuseon, sizeof(reuseon));
+ serv_addr.sin_addr.s_addr = inet_addr(address);
+ serv_addr.sin_port = htons(port);
+ memset( &serv_addr, '\0', sizeof(serv_addr));
+ }
+
+ if (r == -1) {
+ return -1;
+ }
+
+ r = bind(socketfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr));
+ if (r == 0) {
+ return socketfd;
+ } else {
+ return -1;
+ }
+}
+
+int yudpsocket_recive(int socket_fd, char *outdata, int expted_len, char *remoteip, int *remoteport) {
+ struct sockaddr_in cli_addr;
+ socklen_t clilen = sizeof(cli_addr);
+ memset(&cli_addr, 0x0, sizeof(struct sockaddr_in));
+ int len = (int)recvfrom(socket_fd, outdata, expted_len, 0, (struct sockaddr *)&cli_addr, &clilen);
+ char *clientip = inet_ntoa(cli_addr.sin_addr);
+ memcpy(remoteip, clientip, strlen(clientip));
+ *remoteport = cli_addr.sin_port;
+
+ return len;
+}
+
+int yudpsocket_close(int socket_fd) {
+ return close(socket_fd);
+}
+
+//return socket fd
+int yudpsocket_client() {
+ //create socket
+ int socketfd = socket(AF_INET, SOCK_DGRAM, 0);
+ int reuseon = 1;
+ setsockopt(socketfd, SOL_SOCKET, SO_REUSEADDR, &reuseon, sizeof(reuseon));
+
+ return socketfd;
+}
+
+//enable broadcast
+void enable_broadcast(int socket_fd) {
+ int reuseon = 1;
+ setsockopt(socket_fd, SOL_SOCKET, SO_BROADCAST, &reuseon, sizeof(reuseon));
+}
+
+int yudpsocket_get_server_ip(char *host, char *ip) {
+ struct hostent *hp;
+ struct sockaddr_in address;
+
+ hp = gethostbyname(host);
+ if (hp == NULL) {
+ return -1;
+ }
+
+ bcopy((char *)hp->h_addr, (char *)&address.sin_addr, hp->h_length);
+ char *clientip = inet_ntoa(address.sin_addr);
+ memcpy(ip, clientip, strlen(clientip));
+
+ return 0;
+}
+
+//send message to address and port
+int yudpsocket_sentto(int socket_fd, char *msg, int len, char *toaddr, int topotr) {
+ struct sockaddr_in address;
+ socklen_t addrlen = sizeof(address);
+ memset(&address, 0x0, sizeof(struct sockaddr_in));
+ address.sin_family = AF_INET;
+ address.sin_port = htons(topotr);
+ address.sin_addr.s_addr = inet_addr(toaddr);
+ int sendlen = (int)sendto(socket_fd, msg, len, 0, (struct sockaddr *)&address, addrlen);
+
+ return sendlen;
+}
diff --git a/SwiftSocket.podspec b/SwiftSocket.podspec
new file mode 100644
index 0000000..2e4e467
--- /dev/null
+++ b/SwiftSocket.podspec
@@ -0,0 +1,27 @@
+Pod::Spec.new do |s|
+
+ s.name = "SwiftSocket"
+ s.version = "1.2"
+ s.summary = "A cool framework to work with TCP and UDP sockets"
+
+ s.description = <<-DESC
+ SwiftSocket profieds an easy way to create TCP or UDP clients and servers 💁
+ DESC
+
+ s.homepage = "https://github.com/danshevluk/SwiftSocket"
+
+ s.license = { :type => "BSD" }
+
+ s.author = { "Dan Shevlyuk" => "danshevlyuk@icloud.com" }
+ s.social_media_url = "http://twitter.com/danshevluk"
+
+ s.ios.deployment_target = '8.0'
+ # s.osx.deployment_target = '10.7'
+ s.source = {
+ :git => 'https://github.com/danshevluk/SwiftSocket.git',
+ :tag => s.version
+ }
+ s.source_files = 'Sources/**/*'
+ s.pod_target_xcconfig = { 'SWIFT_VERSION' => '3' }
+
+end
diff --git a/SwiftSocket.xcodeproj/project.pbxproj b/SwiftSocket.xcodeproj/project.pbxproj
index ef5b8c7..c9a6084 100644
--- a/SwiftSocket.xcodeproj/project.pbxproj
+++ b/SwiftSocket.xcodeproj/project.pbxproj
@@ -7,70 +7,58 @@
objects = {
/* Begin PBXBuildFile section */
- 55A676E319A5FFCF00663380 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55A676E019A5FFCF00663380 /* main.swift */; };
- D430837D1A565F29004DE4D4 /* ysocket.swift in Sources */ = {isa = PBXBuildFile; fileRef = D43083781A565EBF004DE4D4 /* ysocket.swift */; };
- D430837E1A565F29004DE4D4 /* ytcpsocket.c in Sources */ = {isa = PBXBuildFile; fileRef = D43083791A565EBF004DE4D4 /* ytcpsocket.c */; };
- D430837F1A565F29004DE4D4 /* ytcpsocket.swift in Sources */ = {isa = PBXBuildFile; fileRef = D430837A1A565EBF004DE4D4 /* ytcpsocket.swift */; };
- D43083801A565F29004DE4D4 /* yudpsocket.c in Sources */ = {isa = PBXBuildFile; fileRef = D430837B1A565EBF004DE4D4 /* yudpsocket.c */; };
- D43083811A565F29004DE4D4 /* yudpsocket.swift in Sources */ = {isa = PBXBuildFile; fileRef = D430837C1A565EBF004DE4D4 /* yudpsocket.swift */; };
- D430838C1A565F7F004DE4D4 /* ysocket-ios.h in Headers */ = {isa = PBXBuildFile; fileRef = D430838B1A565F7F004DE4D4 /* ysocket-ios.h */; settings = {ATTRIBUTES = (Public, ); }; };
- D43083A01A565F9F004DE4D4 /* ysocket.swift in Sources */ = {isa = PBXBuildFile; fileRef = D43083781A565EBF004DE4D4 /* ysocket.swift */; };
- D43083A11A565F9F004DE4D4 /* ytcpsocket.c in Sources */ = {isa = PBXBuildFile; fileRef = D43083791A565EBF004DE4D4 /* ytcpsocket.c */; };
- D43083A21A565F9F004DE4D4 /* ytcpsocket.swift in Sources */ = {isa = PBXBuildFile; fileRef = D430837A1A565EBF004DE4D4 /* ytcpsocket.swift */; };
- D43083A31A565F9F004DE4D4 /* yudpsocket.c in Sources */ = {isa = PBXBuildFile; fileRef = D430837B1A565EBF004DE4D4 /* yudpsocket.c */; };
- D43083A41A565F9F004DE4D4 /* yudpsocket.swift in Sources */ = {isa = PBXBuildFile; fileRef = D430837C1A565EBF004DE4D4 /* yudpsocket.swift */; };
- D4F0E40A1A5661260085C247 /* ysocketOSX.h in Headers */ = {isa = PBXBuildFile; fileRef = D4F0E4091A5661260085C247 /* ysocketOSX.h */; settings = {ATTRIBUTES = (Public, ); }; };
- D4F0E41E1A56613C0085C247 /* ysocket.swift in Sources */ = {isa = PBXBuildFile; fileRef = D43083781A565EBF004DE4D4 /* ysocket.swift */; };
- D4F0E41F1A56613C0085C247 /* ytcpsocket.c in Sources */ = {isa = PBXBuildFile; fileRef = D43083791A565EBF004DE4D4 /* ytcpsocket.c */; };
- D4F0E4201A56613C0085C247 /* ytcpsocket.swift in Sources */ = {isa = PBXBuildFile; fileRef = D430837A1A565EBF004DE4D4 /* ytcpsocket.swift */; };
- D4F0E4211A56613C0085C247 /* yudpsocket.c in Sources */ = {isa = PBXBuildFile; fileRef = D430837B1A565EBF004DE4D4 /* yudpsocket.c */; };
- D4F0E4221A56613C0085C247 /* yudpsocket.swift in Sources */ = {isa = PBXBuildFile; fileRef = D430837C1A565EBF004DE4D4 /* yudpsocket.swift */; };
+ 3723138E1DCF84CA0042DA87 /* Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3723138C1DCF84CA0042DA87 /* Info.plist */; };
+ 3723138F1DCF84CA0042DA87 /* SwiftSocket.h in Headers */ = {isa = PBXBuildFile; fileRef = 3723138D1DCF84CA0042DA87 /* SwiftSocket.h */; settings = {ATTRIBUTES = (Public, ); }; };
+ 372313921DCF84D80042DA87 /* UDPClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 372313901DCF84D80042DA87 /* UDPClient.swift */; };
+ 372313931DCF84D80042DA87 /* yudpsocket.c in Sources */ = {isa = PBXBuildFile; fileRef = 372313911DCF84D80042DA87 /* yudpsocket.c */; };
+ 372313961DCF84E30042DA87 /* TCPClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 372313941DCF84E30042DA87 /* TCPClient.swift */; };
+ 372313971DCF84E30042DA87 /* ytcpsocket.c in Sources */ = {isa = PBXBuildFile; fileRef = 372313951DCF84E30042DA87 /* ytcpsocket.c */; };
+ 3723139A1DCF84EC0042DA87 /* Result.swift in Sources */ = {isa = PBXBuildFile; fileRef = 372313981DCF84EC0042DA87 /* Result.swift */; };
+ 3723139B1DCF84EC0042DA87 /* Socket.swift in Sources */ = {isa = PBXBuildFile; fileRef = 372313991DCF84EC0042DA87 /* Socket.swift */; };
+ 3723139C1DCF85270042DA87 /* SwiftSocket.h in Headers */ = {isa = PBXBuildFile; fileRef = 3723138D1DCF84CA0042DA87 /* SwiftSocket.h */; settings = {ATTRIBUTES = (Public, ); }; };
+ 375C48301DDC4C56008C701D /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 375C482F1DDC4C56008C701D /* AppDelegate.swift */; };
+ 375C48321DDC4C56008C701D /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 375C48311DDC4C56008C701D /* ViewController.swift */; };
+ 375C48351DDC4C56008C701D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 375C48331DDC4C56008C701D /* Main.storyboard */; };
+ 375C48371DDC4C56008C701D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 375C48361DDC4C56008C701D /* Assets.xcassets */; };
+ 375C483A1DDC4C56008C701D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 375C48381DDC4C56008C701D /* LaunchScreen.storyboard */; };
/* End PBXBuildFile section */
-/* Begin PBXCopyFilesBuildPhase section */
- 5518C82D19A329100049DC22 /* CopyFiles */ = {
- isa = PBXCopyFilesBuildPhase;
- buildActionMask = 2147483647;
- dstPath = /usr/share/man/man1/;
- dstSubfolderSpec = 0;
- files = (
- );
- runOnlyForDeploymentPostprocessing = 1;
- };
-/* End PBXCopyFilesBuildPhase section */
-
/* Begin PBXFileReference section */
- 5518C82F19A329100049DC22 /* SwiftSocket */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = SwiftSocket; sourceTree = BUILT_PRODUCTS_DIR; };
- 55A676E019A5FFCF00663380 /* main.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = main.swift; path = SwiftSocket/main.swift; sourceTree = SOURCE_ROOT; };
- D43083781A565EBF004DE4D4 /* ysocket.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ysocket.swift; sourceTree = ""; };
- D43083791A565EBF004DE4D4 /* ytcpsocket.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = ytcpsocket.c; sourceTree = ""; };
- D430837A1A565EBF004DE4D4 /* ytcpsocket.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ytcpsocket.swift; sourceTree = ""; };
- D430837B1A565EBF004DE4D4 /* yudpsocket.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = yudpsocket.c; sourceTree = ""; };
- D430837C1A565EBF004DE4D4 /* yudpsocket.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = yudpsocket.swift; sourceTree = ""; };
- D43083871A565F7F004DE4D4 /* ysocket.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = ysocket.framework; sourceTree = BUILT_PRODUCTS_DIR; };
- D430838A1A565F7F004DE4D4 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
- D430838B1A565F7F004DE4D4 /* ysocket-ios.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "ysocket-ios.h"; sourceTree = ""; };
- D4F0E4051A5661260085C247 /* ysocketOSX.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = ysocketOSX.framework; sourceTree = BUILT_PRODUCTS_DIR; };
- D4F0E4081A5661260085C247 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
- D4F0E4091A5661260085C247 /* ysocketOSX.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ysocketOSX.h; sourceTree = ""; };
+ 3723138C1DCF84CA0042DA87 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = Sources/Info.plist; sourceTree = SOURCE_ROOT; };
+ 3723138D1DCF84CA0042DA87 /* SwiftSocket.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SwiftSocket.h; path = Sources/SwiftSocket.h; sourceTree = SOURCE_ROOT; };
+ 372313901DCF84D80042DA87 /* UDPClient.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = UDPClient.swift; path = Sources/UDPClient.swift; sourceTree = SOURCE_ROOT; };
+ 372313911DCF84D80042DA87 /* yudpsocket.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = yudpsocket.c; path = Sources/yudpsocket.c; sourceTree = SOURCE_ROOT; };
+ 372313941DCF84E30042DA87 /* TCPClient.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = TCPClient.swift; path = Sources/TCPClient.swift; sourceTree = SOURCE_ROOT; };
+ 372313951DCF84E30042DA87 /* ytcpsocket.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = ytcpsocket.c; path = Sources/ytcpsocket.c; sourceTree = SOURCE_ROOT; };
+ 372313981DCF84EC0042DA87 /* Result.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Result.swift; path = Sources/Result.swift; sourceTree = SOURCE_ROOT; };
+ 372313991DCF84EC0042DA87 /* Socket.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Socket.swift; path = Sources/Socket.swift; sourceTree = SOURCE_ROOT; };
+ 375C482D1DDC4C56008C701D /* iOS Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "iOS Example.app"; sourceTree = BUILT_PRODUCTS_DIR; };
+ 375C482F1DDC4C56008C701D /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; };
+ 375C48311DDC4C56008C701D /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; };
+ 375C48341DDC4C56008C701D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; };
+ 375C48361DDC4C56008C701D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; };
+ 375C48391DDC4C56008C701D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; };
+ 375C483B1DDC4C56008C701D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
+ 377DAA691DCDE40200009697 /* SwiftSocket.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SwiftSocket.framework; sourceTree = BUILT_PRODUCTS_DIR; };
+ 377DAA761DCDE45D00009697 /* SwiftSocket.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SwiftSocket.framework; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
- 5518C82C19A329100049DC22 /* Frameworks */ = {
+ 375C482A1DDC4C56008C701D /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
- D43083831A565F7F004DE4D4 /* Frameworks */ = {
+ 377DAA651DCDE40200009697 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
- D4F0E4011A5661260085C247 /* Frameworks */ = {
+ 377DAA721DCDE45D00009697 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
@@ -80,156 +68,152 @@
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
- 5518C82619A3290F0049DC22 = {
+ 375BC51D1DCDE86B006AD8F6 /* TCPSocket */ = {
isa = PBXGroup;
children = (
- 5518C83119A329100049DC22 /* SwiftC */,
- D43083881A565F7F004DE4D4 /* ysocket */,
- D4F0E4061A5661260085C247 /* ysocketOSX */,
- 5518C83019A329100049DC22 /* Products */,
+ 372313941DCF84E30042DA87 /* TCPClient.swift */,
+ 372313951DCF84E30042DA87 /* ytcpsocket.c */,
);
+ name = TCPSocket;
sourceTree = "";
};
- 5518C83019A329100049DC22 /* Products */ = {
+ 375BC51E1DCDE878006AD8F6 /* UDPSocket */ = {
isa = PBXGroup;
children = (
- 5518C82F19A329100049DC22 /* SwiftSocket */,
- D43083871A565F7F004DE4D4 /* ysocket.framework */,
- D4F0E4051A5661260085C247 /* ysocketOSX.framework */,
+ 372313901DCF84D80042DA87 /* UDPClient.swift */,
+ 372313911DCF84D80042DA87 /* yudpsocket.c */,
);
- name = Products;
+ name = UDPSocket;
sourceTree = "";
};
- 5518C83119A329100049DC22 /* SwiftC */ = {
+ 375C482E1DDC4C56008C701D /* iOS Example */ = {
isa = PBXGroup;
children = (
- D43083771A565EBF004DE4D4 /* ysocket */,
- 55A676E019A5FFCF00663380 /* main.swift */,
- );
- path = SwiftC;
+ 375C482F1DDC4C56008C701D /* AppDelegate.swift */,
+ 375C48311DDC4C56008C701D /* ViewController.swift */,
+ 375C48331DDC4C56008C701D /* Main.storyboard */,
+ 375C48361DDC4C56008C701D /* Assets.xcassets */,
+ 375C48381DDC4C56008C701D /* LaunchScreen.storyboard */,
+ 375C483B1DDC4C56008C701D /* Info.plist */,
+ );
+ path = "iOS Example";
sourceTree = "";
};
- D43083771A565EBF004DE4D4 /* ysocket */ = {
- isa = PBXGroup;
- children = (
- D43083781A565EBF004DE4D4 /* ysocket.swift */,
- D43083791A565EBF004DE4D4 /* ytcpsocket.c */,
- D430837A1A565EBF004DE4D4 /* ytcpsocket.swift */,
- D430837B1A565EBF004DE4D4 /* yudpsocket.c */,
- D430837C1A565EBF004DE4D4 /* yudpsocket.swift */,
- );
- name = ysocket;
- path = SwiftSocket/ysocket;
- sourceTree = SOURCE_ROOT;
- };
- D43083881A565F7F004DE4D4 /* ysocket */ = {
+ 377DAA6A1DCDE40200009697 /* Supporting Files */ = {
isa = PBXGroup;
children = (
- D430838B1A565F7F004DE4D4 /* ysocket-ios.h */,
- D43083891A565F7F004DE4D4 /* Supporting Files */,
+ 3723138C1DCF84CA0042DA87 /* Info.plist */,
+ 3723138D1DCF84CA0042DA87 /* SwiftSocket.h */,
);
- name = ysocket;
- path = "ysocket-ios";
+ name = "Supporting Files";
+ path = "../SwiftSocket iOS";
sourceTree = "";
};
- D43083891A565F7F004DE4D4 /* Supporting Files */ = {
+ 5518C82619A3290F0049DC22 = {
isa = PBXGroup;
children = (
- D430838A1A565F7F004DE4D4 /* Info.plist */,
+ 5518C83119A329100049DC22 /* Source */,
+ 375C482E1DDC4C56008C701D /* iOS Example */,
+ 5518C83019A329100049DC22 /* Products */,
);
- name = "Supporting Files";
sourceTree = "";
};
- D4F0E4061A5661260085C247 /* ysocketOSX */ = {
+ 5518C83019A329100049DC22 /* Products */ = {
isa = PBXGroup;
children = (
- D4F0E4091A5661260085C247 /* ysocketOSX.h */,
- D4F0E4071A5661260085C247 /* Supporting Files */,
+ 377DAA691DCDE40200009697 /* SwiftSocket.framework */,
+ 377DAA761DCDE45D00009697 /* SwiftSocket.framework */,
+ 375C482D1DDC4C56008C701D /* iOS Example.app */,
);
- path = ysocketOSX;
+ name = Products;
sourceTree = "";
};
- D4F0E4071A5661260085C247 /* Supporting Files */ = {
+ 5518C83119A329100049DC22 /* Source */ = {
isa = PBXGroup;
children = (
- D4F0E4081A5661260085C247 /* Info.plist */,
+ 372313981DCF84EC0042DA87 /* Result.swift */,
+ 372313991DCF84EC0042DA87 /* Socket.swift */,
+ 375BC51D1DCDE86B006AD8F6 /* TCPSocket */,
+ 375BC51E1DCDE878006AD8F6 /* UDPSocket */,
+ 377DAA6A1DCDE40200009697 /* Supporting Files */,
);
- name = "Supporting Files";
+ name = Source;
+ path = SwiftC;
sourceTree = "";
};
/* End PBXGroup section */
/* Begin PBXHeadersBuildPhase section */
- D43083841A565F7F004DE4D4 /* Headers */ = {
+ 377DAA661DCDE40200009697 /* Headers */ = {
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
- D430838C1A565F7F004DE4D4 /* ysocket-ios.h in Headers */,
+ 3723138F1DCF84CA0042DA87 /* SwiftSocket.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
- D4F0E4021A5661260085C247 /* Headers */ = {
+ 377DAA731DCDE45D00009697 /* Headers */ = {
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
- D4F0E40A1A5661260085C247 /* ysocketOSX.h in Headers */,
+ 3723139C1DCF85270042DA87 /* SwiftSocket.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXHeadersBuildPhase section */
/* Begin PBXNativeTarget section */
- 5518C82E19A329100049DC22 /* SwiftSocket */ = {
+ 375C482C1DDC4C56008C701D /* iOS Example */ = {
isa = PBXNativeTarget;
- buildConfigurationList = 5518C83619A329100049DC22 /* Build configuration list for PBXNativeTarget "SwiftSocket" */;
+ buildConfigurationList = 375C483E1DDC4C56008C701D /* Build configuration list for PBXNativeTarget "iOS Example" */;
buildPhases = (
- 5518C82B19A329100049DC22 /* Sources */,
- 5518C82C19A329100049DC22 /* Frameworks */,
- 5518C82D19A329100049DC22 /* CopyFiles */,
+ 375C48291DDC4C56008C701D /* Sources */,
+ 375C482A1DDC4C56008C701D /* Frameworks */,
+ 375C482B1DDC4C56008C701D /* Resources */,
);
buildRules = (
);
dependencies = (
);
- name = SwiftSocket;
- productName = SwiftC;
- productReference = 5518C82F19A329100049DC22 /* SwiftSocket */;
- productType = "com.apple.product-type.tool";
+ name = "iOS Example";
+ productName = "iOS Example";
+ productReference = 375C482D1DDC4C56008C701D /* iOS Example.app */;
+ productType = "com.apple.product-type.application";
};
- D43083861A565F7F004DE4D4 /* ysocket */ = {
+ 377DAA681DCDE40200009697 /* SwiftSocket iOS */ = {
isa = PBXNativeTarget;
- buildConfigurationList = D430839A1A565F7F004DE4D4 /* Build configuration list for PBXNativeTarget "ysocket" */;
+ buildConfigurationList = 377DAA6E1DCDE40200009697 /* Build configuration list for PBXNativeTarget "SwiftSocket iOS" */;
buildPhases = (
- D43083821A565F7F004DE4D4 /* Sources */,
- D43083831A565F7F004DE4D4 /* Frameworks */,
- D43083841A565F7F004DE4D4 /* Headers */,
- D43083851A565F7F004DE4D4 /* Resources */,
+ 377DAA641DCDE40200009697 /* Sources */,
+ 377DAA651DCDE40200009697 /* Frameworks */,
+ 377DAA661DCDE40200009697 /* Headers */,
+ 377DAA671DCDE40200009697 /* Resources */,
);
buildRules = (
);
dependencies = (
);
- name = ysocket;
- productName = "ysocket-ios";
- productReference = D43083871A565F7F004DE4D4 /* ysocket.framework */;
+ name = "SwiftSocket iOS";
+ productName = "SwiftSocket iOS";
+ productReference = 377DAA691DCDE40200009697 /* SwiftSocket.framework */;
productType = "com.apple.product-type.framework";
};
- D4F0E4041A5661260085C247 /* ysocketOSX */ = {
+ 377DAA751DCDE45D00009697 /* SwiftSocket macOS */ = {
isa = PBXNativeTarget;
- buildConfigurationList = D4F0E4181A5661260085C247 /* Build configuration list for PBXNativeTarget "ysocketOSX" */;
+ buildConfigurationList = 377DAA7B1DCDE45D00009697 /* Build configuration list for PBXNativeTarget "SwiftSocket macOS" */;
buildPhases = (
- D4F0E4001A5661260085C247 /* Sources */,
- D4F0E4011A5661260085C247 /* Frameworks */,
- D4F0E4021A5661260085C247 /* Headers */,
- D4F0E4031A5661260085C247 /* Resources */,
+ 377DAA711DCDE45D00009697 /* Sources */,
+ 377DAA721DCDE45D00009697 /* Frameworks */,
+ 377DAA731DCDE45D00009697 /* Headers */,
+ 377DAA741DCDE45D00009697 /* Resources */,
);
buildRules = (
);
dependencies = (
);
- name = ysocketOSX;
- productName = ysocketOSX;
- productReference = D4F0E4051A5661260085C247 /* ysocketOSX.framework */;
+ name = "SwiftSocket macOS";
+ productName = "SwiftSocket macOS";
+ productReference = 377DAA761DCDE45D00009697 /* SwiftSocket.framework */;
productType = "com.apple.product-type.framework";
};
/* End PBXNativeTarget section */
@@ -239,19 +223,22 @@
isa = PBXProject;
attributes = {
LastSwiftMigration = 0710;
- LastSwiftUpdateCheck = 0710;
+ LastSwiftUpdateCheck = 0810;
LastUpgradeCheck = 0710;
ORGANIZATIONNAME = swift;
TargetAttributes = {
- 5518C82E19A329100049DC22 = {
- CreatedOnToolsVersion = 6.0;
- LastSwiftMigration = 0800;
+ 375C482C1DDC4C56008C701D = {
+ CreatedOnToolsVersion = 8.1;
+ ProvisioningStyle = Automatic;
};
- D43083861A565F7F004DE4D4 = {
- CreatedOnToolsVersion = 6.1.1;
+ 377DAA681DCDE40200009697 = {
+ CreatedOnToolsVersion = 8.1;
+ LastSwiftMigration = 0810;
+ ProvisioningStyle = Automatic;
};
- D4F0E4041A5661260085C247 = {
- CreatedOnToolsVersion = 6.1.1;
+ 377DAA751DCDE45D00009697 = {
+ CreatedOnToolsVersion = 8.1;
+ ProvisioningStyle = Automatic;
};
};
};
@@ -261,28 +248,40 @@
hasScannedForEncodings = 0;
knownRegions = (
en,
+ Base,
);
mainGroup = 5518C82619A3290F0049DC22;
productRefGroup = 5518C83019A329100049DC22 /* Products */;
projectDirPath = "";
projectRoot = "";
targets = (
- 5518C82E19A329100049DC22 /* SwiftSocket */,
- D43083861A565F7F004DE4D4 /* ysocket */,
- D4F0E4041A5661260085C247 /* ysocketOSX */,
+ 377DAA681DCDE40200009697 /* SwiftSocket iOS */,
+ 377DAA751DCDE45D00009697 /* SwiftSocket macOS */,
+ 375C482C1DDC4C56008C701D /* iOS Example */,
);
};
/* End PBXProject section */
/* Begin PBXResourcesBuildPhase section */
- D43083851A565F7F004DE4D4 /* Resources */ = {
+ 375C482B1DDC4C56008C701D /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
+ 375C483A1DDC4C56008C701D /* LaunchScreen.storyboard in Resources */,
+ 375C48371DDC4C56008C701D /* Assets.xcassets in Resources */,
+ 375C48351DDC4C56008C701D /* Main.storyboard in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
- D4F0E4031A5661260085C247 /* Resources */ = {
+ 377DAA671DCDE40200009697 /* Resources */ = {
+ isa = PBXResourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 3723138E1DCF84CA0042DA87 /* Info.plist in Resources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+ 377DAA741DCDE45D00009697 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
@@ -292,191 +291,230 @@
/* End PBXResourcesBuildPhase section */
/* Begin PBXSourcesBuildPhase section */
- 5518C82B19A329100049DC22 /* Sources */ = {
+ 375C48291DDC4C56008C701D /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
- D430837D1A565F29004DE4D4 /* ysocket.swift in Sources */,
- D430837E1A565F29004DE4D4 /* ytcpsocket.c in Sources */,
- D430837F1A565F29004DE4D4 /* ytcpsocket.swift in Sources */,
- D43083801A565F29004DE4D4 /* yudpsocket.c in Sources */,
- D43083811A565F29004DE4D4 /* yudpsocket.swift in Sources */,
- 55A676E319A5FFCF00663380 /* main.swift in Sources */,
+ 375C48321DDC4C56008C701D /* ViewController.swift in Sources */,
+ 375C48301DDC4C56008C701D /* AppDelegate.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
- D43083821A565F7F004DE4D4 /* Sources */ = {
+ 377DAA641DCDE40200009697 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
- D43083A01A565F9F004DE4D4 /* ysocket.swift in Sources */,
- D43083A11A565F9F004DE4D4 /* ytcpsocket.c in Sources */,
- D43083A21A565F9F004DE4D4 /* ytcpsocket.swift in Sources */,
- D43083A31A565F9F004DE4D4 /* yudpsocket.c in Sources */,
- D43083A41A565F9F004DE4D4 /* yudpsocket.swift in Sources */,
+ 372313931DCF84D80042DA87 /* yudpsocket.c in Sources */,
+ 3723139A1DCF84EC0042DA87 /* Result.swift in Sources */,
+ 3723139B1DCF84EC0042DA87 /* Socket.swift in Sources */,
+ 372313921DCF84D80042DA87 /* UDPClient.swift in Sources */,
+ 372313971DCF84E30042DA87 /* ytcpsocket.c in Sources */,
+ 372313961DCF84E30042DA87 /* TCPClient.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
- D4F0E4001A5661260085C247 /* Sources */ = {
+ 377DAA711DCDE45D00009697 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
- D4F0E41E1A56613C0085C247 /* ysocket.swift in Sources */,
- D4F0E41F1A56613C0085C247 /* ytcpsocket.c in Sources */,
- D4F0E4201A56613C0085C247 /* ytcpsocket.swift in Sources */,
- D4F0E4211A56613C0085C247 /* yudpsocket.c in Sources */,
- D4F0E4221A56613C0085C247 /* yudpsocket.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */
+/* Begin PBXVariantGroup section */
+ 375C48331DDC4C56008C701D /* Main.storyboard */ = {
+ isa = PBXVariantGroup;
+ children = (
+ 375C48341DDC4C56008C701D /* Base */,
+ );
+ name = Main.storyboard;
+ sourceTree = "";
+ };
+ 375C48381DDC4C56008C701D /* LaunchScreen.storyboard */ = {
+ isa = PBXVariantGroup;
+ children = (
+ 375C48391DDC4C56008C701D /* Base */,
+ );
+ name = LaunchScreen.storyboard;
+ sourceTree = "";
+ };
+/* End PBXVariantGroup section */
+
/* Begin XCBuildConfiguration section */
- 5518C83419A329100049DC22 /* Debug */ = {
+ 375C483C1DDC4C56008C701D /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
- ALWAYS_SEARCH_USER_PATHS = NO;
- CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
- CLANG_CXX_LIBRARY = "libc++";
- CLANG_ENABLE_MODULES = YES;
- CLANG_ENABLE_OBJC_ARC = YES;
- CLANG_WARN_BOOL_CONVERSION = YES;
- CLANG_WARN_CONSTANT_CONVERSION = YES;
- CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
- CLANG_WARN_EMPTY_BODY = YES;
- CLANG_WARN_ENUM_CONVERSION = YES;
- CLANG_WARN_INT_CONVERSION = YES;
- CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
- CLANG_WARN_UNREACHABLE_CODE = YES;
- CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
- COPY_PHASE_STRIP = NO;
- ENABLE_STRICT_OBJC_MSGSEND = YES;
- ENABLE_TESTABILITY = YES;
- GCC_C_LANGUAGE_STANDARD = gnu99;
- GCC_DYNAMIC_NO_PIC = NO;
- GCC_OPTIMIZATION_LEVEL = 0;
- GCC_PREPROCESSOR_DEFINITIONS = (
- "DEBUG=1",
- "$(inherited)",
- );
- GCC_SYMBOLS_PRIVATE_EXTERN = NO;
- GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
- GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
- GCC_WARN_UNDECLARED_SELECTOR = YES;
- GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
- GCC_WARN_UNUSED_FUNCTION = YES;
- GCC_WARN_UNUSED_VARIABLE = YES;
- MACOSX_DEPLOYMENT_TARGET = 10.11;
- MTL_ENABLE_DEBUG_INFO = YES;
- ONLY_ACTIVE_ARCH = YES;
- SDKROOT = macosx;
- SWIFT_OPTIMIZATION_LEVEL = "-Onone";
- SWIFT_VERSION = "";
+ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
+ CLANG_ANALYZER_NONNULL = YES;
+ CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
+ CLANG_WARN_INFINITE_RECURSION = YES;
+ CLANG_WARN_SUSPICIOUS_MOVES = YES;
+ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
+ DEBUG_INFORMATION_FORMAT = dwarf;
+ GCC_NO_COMMON_BLOCKS = YES;
+ INFOPLIST_FILE = "iOS Example/Info.plist";
+ IPHONEOS_DEPLOYMENT_TARGET = 10.1;
+ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
+ PRODUCT_BUNDLE_IDENTIFIER = "com.danshevluk.iOS-Example";
+ PRODUCT_NAME = "$(TARGET_NAME)";
+ SDKROOT = iphoneos;
+ SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
+ SWIFT_VERSION = 3.0;
+ TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
};
- 5518C83519A329100049DC22 /* Release */ = {
+ 375C483D1DDC4C56008C701D /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
- ALWAYS_SEARCH_USER_PATHS = NO;
- CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
- CLANG_CXX_LIBRARY = "libc++";
- CLANG_ENABLE_MODULES = YES;
- CLANG_ENABLE_OBJC_ARC = YES;
- CLANG_WARN_BOOL_CONVERSION = YES;
- CLANG_WARN_CONSTANT_CONVERSION = YES;
- CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
- CLANG_WARN_EMPTY_BODY = YES;
- CLANG_WARN_ENUM_CONVERSION = YES;
- CLANG_WARN_INT_CONVERSION = YES;
- CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
- CLANG_WARN_UNREACHABLE_CODE = YES;
- CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
- COPY_PHASE_STRIP = YES;
- DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
- ENABLE_NS_ASSERTIONS = NO;
- ENABLE_STRICT_OBJC_MSGSEND = YES;
- GCC_C_LANGUAGE_STANDARD = gnu99;
- GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
- GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
- GCC_WARN_UNDECLARED_SELECTOR = YES;
- GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
- GCC_WARN_UNUSED_FUNCTION = YES;
- GCC_WARN_UNUSED_VARIABLE = YES;
- MACOSX_DEPLOYMENT_TARGET = 10.11;
- MTL_ENABLE_DEBUG_INFO = NO;
- SDKROOT = macosx;
- SWIFT_VERSION = "";
+ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
+ CLANG_ANALYZER_NONNULL = YES;
+ CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
+ CLANG_WARN_INFINITE_RECURSION = YES;
+ CLANG_WARN_SUSPICIOUS_MOVES = YES;
+ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
+ COPY_PHASE_STRIP = NO;
+ GCC_NO_COMMON_BLOCKS = YES;
+ INFOPLIST_FILE = "iOS Example/Info.plist";
+ IPHONEOS_DEPLOYMENT_TARGET = 10.1;
+ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
+ PRODUCT_BUNDLE_IDENTIFIER = "com.danshevluk.iOS-Example";
+ PRODUCT_NAME = "$(TARGET_NAME)";
+ SDKROOT = iphoneos;
+ SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
+ SWIFT_VERSION = 3.0;
+ TARGETED_DEVICE_FAMILY = "1,2";
+ VALIDATE_PRODUCT = YES;
};
name = Release;
};
- 5518C83719A329100049DC22 /* Debug */ = {
+ 377DAA6F1DCDE40200009697 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ CLANG_ANALYZER_NONNULL = YES;
CLANG_ENABLE_MODULES = YES;
- LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
+ CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
+ CLANG_WARN_INFINITE_RECURSION = YES;
+ CLANG_WARN_SUSPICIOUS_MOVES = YES;
+ CODE_SIGN_IDENTITY = "";
+ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
+ CURRENT_PROJECT_VERSION = 1;
+ DEBUG_INFORMATION_FORMAT = dwarf;
+ DEFINES_MODULE = YES;
+ DYLIB_COMPATIBILITY_VERSION = 1;
+ DYLIB_CURRENT_VERSION = 1;
+ DYLIB_INSTALL_NAME_BASE = "@rpath";
+ GCC_NO_COMMON_BLOCKS = YES;
+ INFOPLIST_FILE = "$(SRCROOT)/Sources/Info.plist";
+ INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
+ IPHONEOS_DEPLOYMENT_TARGET = 9.0;
+ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
+ PRODUCT_BUNDLE_IDENTIFIER = com.danshevluk.SwiftSocket;
PRODUCT_NAME = SwiftSocket;
- SWIFT_OBJC_BRIDGING_HEADER = "";
+ SDKROOT = iphoneos;
+ SKIP_INSTALL = YES;
+ SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
+ TARGETED_DEVICE_FAMILY = "1,2";
+ VERSIONING_SYSTEM = "apple-generic";
+ VERSION_INFO_PREFIX = "";
};
name = Debug;
};
- 5518C83819A329100049DC22 /* Release */ = {
+ 377DAA701DCDE40200009697 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ CLANG_ANALYZER_NONNULL = YES;
CLANG_ENABLE_MODULES = YES;
- LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
+ CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
+ CLANG_WARN_INFINITE_RECURSION = YES;
+ CLANG_WARN_SUSPICIOUS_MOVES = YES;
+ CODE_SIGN_IDENTITY = "";
+ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
+ COPY_PHASE_STRIP = NO;
+ CURRENT_PROJECT_VERSION = 1;
+ DEFINES_MODULE = YES;
+ DYLIB_COMPATIBILITY_VERSION = 1;
+ DYLIB_CURRENT_VERSION = 1;
+ DYLIB_INSTALL_NAME_BASE = "@rpath";
+ GCC_NO_COMMON_BLOCKS = YES;
+ INFOPLIST_FILE = "$(SRCROOT)/Sources/Info.plist";
+ INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
+ IPHONEOS_DEPLOYMENT_TARGET = 9.0;
+ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
+ PRODUCT_BUNDLE_IDENTIFIER = com.danshevluk.SwiftSocket;
PRODUCT_NAME = SwiftSocket;
- SWIFT_OBJC_BRIDGING_HEADER = "";
+ SDKROOT = iphoneos;
+ SKIP_INSTALL = YES;
+ SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
+ TARGETED_DEVICE_FAMILY = "1,2";
+ VALIDATE_PRODUCT = YES;
+ VERSIONING_SYSTEM = "apple-generic";
+ VERSION_INFO_PREFIX = "";
};
name = Release;
};
- D430839B1A565F7F004DE4D4 /* Debug */ = {
+ 377DAA7C1DCDE45D00009697 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ CLANG_ANALYZER_NONNULL = YES;
+ CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
+ CLANG_WARN_INFINITE_RECURSION = YES;
+ CLANG_WARN_SUSPICIOUS_MOVES = YES;
+ CODE_SIGN_IDENTITY = "";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CURRENT_PROJECT_VERSION = 1;
+ DEBUG_INFORMATION_FORMAT = dwarf;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
- GCC_PREPROCESSOR_DEFINITIONS = (
- "DEBUG=1",
- "$(inherited)",
- );
- INFOPLIST_FILE = "ysocket-ios/Info.plist";
+ GCC_NO_COMMON_BLOCKS = YES;
+ INFOPLIST_FILE = "$(SRCROOT)/Sources/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
- IPHONEOS_DEPLOYMENT_TARGET = 8.1;
+ IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
- PRODUCT_BUNDLE_IDENTIFIER = "ixy.io.$(PRODUCT_NAME:rfc1034identifier)";
- PRODUCT_NAME = "$(TARGET_NAME)";
+ PRODUCT_BUNDLE_IDENTIFIER = com.danshevluk.SwiftSocket;
+ PRODUCT_NAME = SwiftSocket;
SDKROOT = iphoneos;
SKIP_INSTALL = YES;
+ SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
+ SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
};
name = Debug;
};
- D430839C1A565F7F004DE4D4 /* Release */ = {
+ 377DAA7D1DCDE45D00009697 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ CLANG_ANALYZER_NONNULL = YES;
+ CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
+ CLANG_WARN_INFINITE_RECURSION = YES;
+ CLANG_WARN_SUSPICIOUS_MOVES = YES;
+ CODE_SIGN_IDENTITY = "";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
+ COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 1;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
- INFOPLIST_FILE = "ysocket-ios/Info.plist";
+ GCC_NO_COMMON_BLOCKS = YES;
+ INFOPLIST_FILE = "$(SRCROOT)/Sources/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
- IPHONEOS_DEPLOYMENT_TARGET = 8.1;
+ IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
- PRODUCT_BUNDLE_IDENTIFIER = "ixy.io.$(PRODUCT_NAME:rfc1034identifier)";
- PRODUCT_NAME = "$(TARGET_NAME)";
+ PRODUCT_BUNDLE_IDENTIFIER = com.danshevluk.SwiftSocket;
+ PRODUCT_NAME = SwiftSocket;
SDKROOT = iphoneos;
SKIP_INSTALL = YES;
+ SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
+ SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
VERSIONING_SYSTEM = "apple-generic";
@@ -484,91 +522,122 @@
};
name = Release;
};
- D4F0E4191A5661260085C247 /* Debug */ = {
+ 5518C83419A329100049DC22 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
- COMBINE_HIDPI_IMAGES = YES;
- CURRENT_PROJECT_VERSION = 1;
- DEFINES_MODULE = YES;
- DYLIB_COMPATIBILITY_VERSION = 1;
- DYLIB_CURRENT_VERSION = 1;
- DYLIB_INSTALL_NAME_BASE = "@rpath";
- EMBEDDED_CONTENT_CONTAINS_SWIFT = YES;
- FRAMEWORK_VERSION = A;
+ ALWAYS_SEARCH_USER_PATHS = NO;
+ CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
+ CLANG_CXX_LIBRARY = "libc++";
+ CLANG_ENABLE_MODULES = YES;
+ CLANG_ENABLE_OBJC_ARC = YES;
+ CLANG_WARN_BOOL_CONVERSION = YES;
+ CLANG_WARN_CONSTANT_CONVERSION = YES;
+ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
+ CLANG_WARN_EMPTY_BODY = YES;
+ CLANG_WARN_ENUM_CONVERSION = YES;
+ CLANG_WARN_INT_CONVERSION = YES;
+ CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
+ CLANG_WARN_UNREACHABLE_CODE = YES;
+ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
+ COPY_PHASE_STRIP = NO;
+ ENABLE_STRICT_OBJC_MSGSEND = YES;
+ ENABLE_TESTABILITY = YES;
+ GCC_C_LANGUAGE_STANDARD = gnu99;
+ GCC_DYNAMIC_NO_PIC = NO;
+ GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
);
- INFOPLIST_FILE = ysocketOSX/Info.plist;
- INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
- LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
+ GCC_SYMBOLS_PRIVATE_EXTERN = NO;
+ GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+ GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
+ GCC_WARN_UNDECLARED_SELECTOR = YES;
+ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
+ GCC_WARN_UNUSED_FUNCTION = YES;
+ GCC_WARN_UNUSED_VARIABLE = YES;
+ IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MACOSX_DEPLOYMENT_TARGET = 10.11;
- PRODUCT_BUNDLE_IDENTIFIER = "ixy.io.$(PRODUCT_NAME:rfc1034identifier)";
- PRODUCT_NAME = "$(TARGET_NAME)";
- SKIP_INSTALL = YES;
- VERSIONING_SYSTEM = "apple-generic";
- VERSION_INFO_PREFIX = "";
+ MTL_ENABLE_DEBUG_INFO = YES;
+ ONLY_ACTIVE_ARCH = YES;
+ PRODUCT_NAME = "";
+ SDKROOT = macosx;
+ SWIFT_OPTIMIZATION_LEVEL = "-Onone";
+ SWIFT_VERSION = 3.0;
};
name = Debug;
};
- D4F0E41A1A5661260085C247 /* Release */ = {
+ 5518C83519A329100049DC22 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
- COMBINE_HIDPI_IMAGES = YES;
- CURRENT_PROJECT_VERSION = 1;
- DEFINES_MODULE = YES;
- DYLIB_COMPATIBILITY_VERSION = 1;
- DYLIB_CURRENT_VERSION = 1;
- DYLIB_INSTALL_NAME_BASE = "@rpath";
- EMBEDDED_CONTENT_CONTAINS_SWIFT = YES;
- FRAMEWORK_VERSION = A;
- INFOPLIST_FILE = ysocketOSX/Info.plist;
- INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
- LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
+ ALWAYS_SEARCH_USER_PATHS = NO;
+ CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
+ CLANG_CXX_LIBRARY = "libc++";
+ CLANG_ENABLE_MODULES = YES;
+ CLANG_ENABLE_OBJC_ARC = YES;
+ CLANG_WARN_BOOL_CONVERSION = YES;
+ CLANG_WARN_CONSTANT_CONVERSION = YES;
+ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
+ CLANG_WARN_EMPTY_BODY = YES;
+ CLANG_WARN_ENUM_CONVERSION = YES;
+ CLANG_WARN_INT_CONVERSION = YES;
+ CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
+ CLANG_WARN_UNREACHABLE_CODE = YES;
+ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
+ COPY_PHASE_STRIP = YES;
+ DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
+ ENABLE_NS_ASSERTIONS = NO;
+ ENABLE_STRICT_OBJC_MSGSEND = YES;
+ GCC_C_LANGUAGE_STANDARD = gnu99;
+ GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+ GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
+ GCC_WARN_UNDECLARED_SELECTOR = YES;
+ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
+ GCC_WARN_UNUSED_FUNCTION = YES;
+ GCC_WARN_UNUSED_VARIABLE = YES;
+ IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MACOSX_DEPLOYMENT_TARGET = 10.11;
- PRODUCT_BUNDLE_IDENTIFIER = "ixy.io.$(PRODUCT_NAME:rfc1034identifier)";
- PRODUCT_NAME = "$(TARGET_NAME)";
- SKIP_INSTALL = YES;
- VERSIONING_SYSTEM = "apple-generic";
- VERSION_INFO_PREFIX = "";
+ MTL_ENABLE_DEBUG_INFO = NO;
+ PRODUCT_NAME = "";
+ SDKROOT = macosx;
+ SWIFT_VERSION = 3.0;
};
name = Release;
};
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
- 5518C82A19A3290F0049DC22 /* Build configuration list for PBXProject "SwiftSocket" */ = {
+ 375C483E1DDC4C56008C701D /* Build configuration list for PBXNativeTarget "iOS Example" */ = {
isa = XCConfigurationList;
buildConfigurations = (
- 5518C83419A329100049DC22 /* Debug */,
- 5518C83519A329100049DC22 /* Release */,
+ 375C483C1DDC4C56008C701D /* Debug */,
+ 375C483D1DDC4C56008C701D /* Release */,
);
defaultConfigurationIsVisible = 0;
- defaultConfigurationName = Release;
};
- 5518C83619A329100049DC22 /* Build configuration list for PBXNativeTarget "SwiftSocket" */ = {
+ 377DAA6E1DCDE40200009697 /* Build configuration list for PBXNativeTarget "SwiftSocket iOS" */ = {
isa = XCConfigurationList;
buildConfigurations = (
- 5518C83719A329100049DC22 /* Debug */,
- 5518C83819A329100049DC22 /* Release */,
+ 377DAA6F1DCDE40200009697 /* Debug */,
+ 377DAA701DCDE40200009697 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
- D430839A1A565F7F004DE4D4 /* Build configuration list for PBXNativeTarget "ysocket" */ = {
+ 377DAA7B1DCDE45D00009697 /* Build configuration list for PBXNativeTarget "SwiftSocket macOS" */ = {
isa = XCConfigurationList;
buildConfigurations = (
- D430839B1A565F7F004DE4D4 /* Debug */,
- D430839C1A565F7F004DE4D4 /* Release */,
+ 377DAA7C1DCDE45D00009697 /* Debug */,
+ 377DAA7D1DCDE45D00009697 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
- D4F0E4181A5661260085C247 /* Build configuration list for PBXNativeTarget "ysocketOSX" */ = {
+ 5518C82A19A3290F0049DC22 /* Build configuration list for PBXProject "SwiftSocket" */ = {
isa = XCConfigurationList;
buildConfigurations = (
- D4F0E4191A5661260085C247 /* Debug */,
- D4F0E41A1A5661260085C247 /* Release */,
+ 5518C83419A329100049DC22 /* Debug */,
+ 5518C83519A329100049DC22 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
diff --git a/SwiftSocket.xcodeproj/xcshareddata/xcschemes/SwiftSocket.xcscheme b/SwiftSocket.xcodeproj/xcshareddata/xcschemes/SwiftSocket.xcscheme
deleted file mode 100644
index ca34095..0000000
--- a/SwiftSocket.xcodeproj/xcshareddata/xcschemes/SwiftSocket.xcscheme
+++ /dev/null
@@ -1,91 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/SwiftSocket.xcodeproj/xcshareddata/xcschemes/ysocket.xcscheme b/SwiftSocket.xcodeproj/xcshareddata/xcschemes/ysocket.xcscheme
deleted file mode 100644
index 0bcd043..0000000
--- a/SwiftSocket.xcodeproj/xcshareddata/xcschemes/ysocket.xcscheme
+++ /dev/null
@@ -1,80 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/SwiftSocket.xcodeproj/xcshareddata/xcschemes/ysocketOSX.xcscheme b/SwiftSocket.xcodeproj/xcshareddata/xcschemes/ysocketOSX.xcscheme
deleted file mode 100644
index f2bbd50..0000000
--- a/SwiftSocket.xcodeproj/xcshareddata/xcschemes/ysocketOSX.xcscheme
+++ /dev/null
@@ -1,80 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/SwiftSocket/main.swift b/SwiftSocket/main.swift
deleted file mode 100644
index 1d21fe4..0000000
--- a/SwiftSocket/main.swift
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
-Copyright (c) <2014>, skysent
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-1. Redistributions of source code must retain the above copyright
-notice, this list of conditions and the following disclaimer.
-2. Redistributions in binary form must reproduce the above copyright
-notice, this list of conditions and the following disclaimer in the
-documentation and/or other materials provided with the distribution.
-3. All advertising materials mentioning features or use of this software
-must display the following acknowledgement:
-This product includes software developed by skysent.
-4. Neither the name of the skysent nor the
-names of its contributors may be used to endorse or promote products
-derived from this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY skysent ''AS IS'' AND ANY
-EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-DISCLAIMED. IN NO EVENT SHALL skysent BE LIABLE FOR ANY
-DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-import Foundation
-import Darwin.C
-func testtcpclient(){
- //创建socket
- let client:TCPClient = TCPClient(addr: "ixy.io", port: 80)
- //连接
- var (success,errmsg)=client.connect(timeout: 1)
- if success{
- //发送数据
- var (success,errmsg)=client.send(str:"GET / HTTP/1.0\n\n" )
- if success{
- //读取数据
- let data=client.read(1024*10)
- if let d=data{
- if let str=String(bytes: d, encoding: String.Encoding.utf8){
- print(str)
- }
- }
- }else{
- print(errmsg)
- }
- }else{
- print(errmsg)
- }
-}
-func echoService(client c:TCPClient){
- print("newclient from:\(c.addr)[\(c.port)]")
- let d=c.read(1024*10)
- c.send(data: d!)
- c.close()
-}
-func testtcpserver(){
- let server:TCPServer = TCPServer(addr: "127.0.0.1", port: 8080)
- var (success,msg)=server.listen()
- if success{
- while true{
- if let client=server.accept(){
- echoService(client: client)
- }else{
- print("accept error")
- }
- }
- }else{
- print(msg)
- }
-}
-//testclient()
-func testudpserver(){
- DispatchQueue.global(priority: DispatchQueue.GlobalQueuePriority.background).async(execute: { () -> Void in
- let server:UDPServer=UDPServer(addr:"127.0.0.1",port:8080)
- let run:Bool=true
- while run{
- var (data,remoteip,remoteport)=server.recv(1024)
- print("recive")
- if let d=data{
- if let str=String(bytes: d, encoding: String.Encoding.utf8){
- print(str)
- }
- }
- print(remoteip)
- server.close()
- break
- }
- })
-}
-func testudpclient(){
- let client:UDPClient=UDPClient(addr: "localhost", port: 8080)
- print("send hello world")
- client.send(str: "hello world")
- client.close()
-}
-//testudpBroadcastclient()
-func testudpBroadcastserver(){
- DispatchQueue.global(priority: DispatchQueue.GlobalQueuePriority.background).async(execute: { () -> Void in
- //turn the server to broadcast mode with the address 255.255.255.255 or empty string
- let server:UDPServer=UDPServer(addr:"",port:8080)
- let run:Bool=true
- print("server.started")
- while run{
- let (data,remoteip,remoteport)=server.recv(1024)
- print("recive\(remoteip);\(remoteport)")
- if let d=data{
- if let str=String(bytes: d, encoding: String.Encoding.utf8){
- print(str)
- }
- }
- print(remoteip)
- }
- print("server.close")
- server.close()
- })
-}
-func testudpBroadcastclient(){
- //wait a few second till server will ready
- sleep(2)
- print("Broadcastclient.send...")
- let clientB:UDPClient = UDPClient(addr: "255.255.255.255", port: 8080)
- clientB.enableBroadcast()
- clientB.send(str: "test hello from broadcast")
- clientB.close()
-}
-//testudpserver()
-//testudpclient()
-
-testudpBroadcastserver()
-testudpBroadcastclient()
-
-var stdinput=FileHandle.standardInput
-stdinput.readDataToEndOfFile()
-
diff --git a/SwiftSocket/ysocket/ysocket.swift b/SwiftSocket/ysocket/ysocket.swift
deleted file mode 100644
index b4b580c..0000000
--- a/SwiftSocket/ysocket/ysocket.swift
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
-Copyright (c) <2014>, skysent
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-1. Redistributions of source code must retain the above copyright
-notice, this list of conditions and the following disclaimer.
-2. Redistributions in binary form must reproduce the above copyright
-notice, this list of conditions and the following disclaimer in the
-documentation and/or other materials provided with the distribution.
-3. All advertising materials mentioning features or use of this software
-must display the following acknowledgement:
-This product includes software developed by skysent.
-4. Neither the name of the skysent nor the
-names of its contributors may be used to endorse or promote products
-derived from this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY skysent ''AS IS'' AND ANY
-EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-DISCLAIMED. IN NO EVENT SHALL skysent BE LIABLE FOR ANY
-DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-import Foundation
-open class YSocket{
- var addr:String
- var port:Int
- var fd:Int32?
- init(){
- self.addr=""
- self.port=0
- }
- public init(addr a:String,port p:Int){
- self.addr=a
- self.port=p
- }
-}
diff --git a/SwiftSocket/ysocket/ytcpsocket.c b/SwiftSocket/ysocket/ytcpsocket.c
deleted file mode 100644
index c65b2ff..0000000
--- a/SwiftSocket/ysocket/ytcpsocket.c
+++ /dev/null
@@ -1,163 +0,0 @@
-/*
- Copyright (c) <2014>, skysent
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
- 3. All advertising materials mentioning features or use of this software
- must display the following acknowledgement:
- This product includes software developed by skysent.
- 4. Neither the name of the skysent nor the
- names of its contributors may be used to endorse or promote products
- derived from this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY skysent ''AS IS'' AND ANY
- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- DISCLAIMED. IN NO EVENT SHALL skysent BE LIABLE FOR ANY
- DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-void ytcpsocket_set_block(int socket,int on) {
- int flags;
- flags = fcntl(socket,F_GETFL,0);
- if (on==0) {
- fcntl(socket, F_SETFL, flags | O_NONBLOCK);
- }else{
- flags &= ~ O_NONBLOCK;
- fcntl(socket, F_SETFL, flags);
- }
-}
-int ytcpsocket_connect(const char *host,int port,int timeout){
- struct sockaddr_in sa;
- struct hostent *hp;
- int sockfd = -1;
- hp = gethostbyname(host);
- if(hp==NULL){
- return -1;
- }
- bcopy((char *)hp->h_addr, (char *)&sa.sin_addr, hp->h_length);
- sa.sin_family = hp->h_addrtype;
- sa.sin_port = htons(port);
- sockfd = socket(hp->h_addrtype, SOCK_STREAM, 0);
- ytcpsocket_set_block(sockfd,0);
- connect(sockfd, (struct sockaddr *)&sa, sizeof(sa));
- fd_set fdwrite;
- struct timeval tvSelect;
- FD_ZERO(&fdwrite);
- FD_SET(sockfd, &fdwrite);
- tvSelect.tv_sec = timeout;
- tvSelect.tv_usec = 0;
- int retval = select(sockfd + 1,NULL, &fdwrite, NULL, &tvSelect);
- if (retval<0) {
- close(sockfd);
- return -2;
- }else if(retval==0){//timeout
- close(sockfd);
- return -3;
- }else{
- int error=0;
- int errlen=sizeof(error);
- getsockopt(sockfd, SOL_SOCKET, SO_ERROR, &error, (socklen_t *)&errlen);
- if(error!=0){
- close(sockfd);
- return -4;//connect fail
- }
- ytcpsocket_set_block(sockfd, 1);
- int set = 1;
- setsockopt(sockfd, SOL_SOCKET, SO_NOSIGPIPE, (void *)&set, sizeof(int));
- return sockfd;
- }
-}
-int ytcpsocket_close(int socketfd){
- return close(socketfd);
-}
-int ytcpsocket_pull(int socketfd,char *data,int len,int timeout_sec){
- if (timeout_sec>0) {
- fd_set fdset;
- struct timeval timeout;
- timeout.tv_usec = 0;
- timeout.tv_sec = timeout_sec;
- FD_ZERO(&fdset);
- FD_SET(socketfd, &fdset);
- int ret = select(socketfd+1, &fdset, NULL, NULL, &timeout);
- if (ret<=0) {
- return ret; // select-call failed or timeout occurred (before anything was sent)
- }
- }
- int readlen=(int)read(socketfd,data,len);
- return readlen;
-}
-int ytcpsocket_send(int socketfd,const char *data,int len){
- int byteswrite=0;
- while (len-byteswrite>0) {
- int writelen=(int)write(socketfd, data+byteswrite, len-byteswrite);
- if (writelen<0) {
- return -1;
- }
- byteswrite+=writelen;
- }
- return byteswrite;
-}
-//return socket fd
-int ytcpsocket_listen(const char *addr,int port){
- //create socket
- int socketfd=socket(AF_INET, SOCK_STREAM, 0);
- int reuseon = 1;
- setsockopt( socketfd, SOL_SOCKET, SO_REUSEADDR, &reuseon, sizeof(reuseon) );
- //bind
- struct sockaddr_in serv_addr;
- memset( &serv_addr, '\0', sizeof(serv_addr));
- serv_addr.sin_family = AF_INET;
- serv_addr.sin_addr.s_addr = inet_addr(addr);
- serv_addr.sin_port = htons(port);
- int r=bind(socketfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr));
- if(r==0){
- if (listen(socketfd, 128)==0) {
- return socketfd;
- }else{
- return -2;//listen error
- }
- }else{
- return -1;//bind error
- }
-}
-//return client socket fd
-int ytcpsocket_accept(int onsocketfd,char *remoteip,int* remoteport){
- socklen_t clilen;
- struct sockaddr_in cli_addr;
- clilen = sizeof(cli_addr);
- int newsockfd = accept(onsocketfd, (struct sockaddr *) &cli_addr, &clilen);
- char *clientip=inet_ntoa(cli_addr.sin_addr);
- memcpy(remoteip, clientip, strlen(clientip));
- *remoteport=cli_addr.sin_port;
- if(newsockfd>0){
- return newsockfd;
- }else{
- return -1;
- }
-}
diff --git a/SwiftSocket/ysocket/ytcpsocket.swift b/SwiftSocket/ysocket/ytcpsocket.swift
deleted file mode 100644
index fc2d7e4..0000000
--- a/SwiftSocket/ysocket/ytcpsocket.swift
+++ /dev/null
@@ -1,185 +0,0 @@
-/*
-Copyright (c) <2014>, skysent
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-1. Redistributions of source code must retain the above copyright
-notice, this list of conditions and the following disclaimer.
-2. Redistributions in binary form must reproduce the above copyright
-notice, this list of conditions and the following disclaimer in the
-documentation and/or other materials provided with the distribution.
-3. All advertising materials mentioning features or use of this software
-must display the following acknowledgement:
-This product includes software developed by skysent.
-4. Neither the name of the skysent nor the
-names of its contributors may be used to endorse or promote products
-derived from this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY skysent ''AS IS'' AND ANY
-EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-DISCLAIMED. IN NO EVENT SHALL skysent BE LIABLE FOR ANY
-DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-import Foundation
-
-@_silgen_name("ytcpsocket_connect") func c_ytcpsocket_connect(_ host:UnsafePointer,port:Int32,timeout:Int32) -> Int32
-@_silgen_name("ytcpsocket_close") func c_ytcpsocket_close(_ fd:Int32) -> Int32
-@_silgen_name("ytcpsocket_send") func c_ytcpsocket_send(_ fd:Int32,buff:UnsafePointer,len:Int32) -> Int32
-@_silgen_name("ytcpsocket_pull") func c_ytcpsocket_pull(_ fd:Int32,buff:UnsafePointer,len:Int32,timeout:Int32) -> Int32
-@_silgen_name("ytcpsocket_listen") func c_ytcpsocket_listen(_ addr:UnsafePointer,port:Int32)->Int32
-@_silgen_name("ytcpsocket_accept") func c_ytcpsocket_accept(_ onsocketfd:Int32,ip:UnsafePointer,port:UnsafePointer) -> Int32
-
-open class TCPClient:YSocket{
- /*
- * connect to server
- * return success or fail with message
- */
- open func connect(timeout t:Int)->(Bool,String){
- let rs:Int32=c_ytcpsocket_connect(self.addr, port: Int32(self.port), timeout: Int32(t))
- if rs>0{
- self.fd=rs
- return (true,"connect success")
- }else{
- switch rs{
- case -1:
- return (false,"qeury server fail")
- case -2:
- return (false,"connection closed")
- case -3:
- return (false,"connect timeout")
- default:
- return (false,"unknow err.")
- }
- }
- }
- /*
- * close socket
- * return success or fail with message
- */
- open func close()->(Bool,String){
- if let fd:Int32=self.fd{
- c_ytcpsocket_close(fd)
- self.fd=nil
- return (true,"close success")
- }else{
- return (false,"socket not open")
- }
- }
- /*
- * send data
- * return success or fail with message
- */
- open func send(data d:[UInt8])->(Bool,String){
- if let fd:Int32=self.fd{
- let sendsize:Int32=c_ytcpsocket_send(fd, buff: d, len: Int32(d.count))
- if Int(sendsize)==d.count{
- return (true,"send success")
- }else{
- return (false,"send error")
- }
- }else{
- return (false,"socket not open")
- }
- }
- /*
- * send string
- * return success or fail with message
- */
- open func send(str s:String)->(Bool,String){
- if let fd:Int32=self.fd{
- let sendsize:Int32=c_ytcpsocket_send(fd, buff: s, len: Int32(strlen(s)))
- if sendsize==Int32(strlen(s)){
- return (true,"send success")
- }else{
- return (false,"send error")
- }
- }else{
- return (false,"socket not open")
- }
- }
- /*
- *
- * send nsdata
- */
- open func send(data d:Data)->(Bool,String){
- if let fd:Int32=self.fd{
- var buff:[UInt8] = [UInt8](repeating: 0x0,count: d.count)
- (d as NSData).getBytes(&buff, length: d.count)
- let sendsize:Int32=c_ytcpsocket_send(fd, buff: buff, len: Int32(d.count))
- if sendsize==Int32(d.count){
- return (true,"send success")
- }else{
- return (false,"send error")
- }
- }else{
- return (false,"socket not open")
- }
- }
- /*
- * read data with expect length
- * return success or fail with message
- */
- open func read(_ expectlen:Int, timeout:Int = -1)->[UInt8]?{
- if let fd:Int32 = self.fd{
- var buff:[UInt8] = [UInt8](repeating: 0x0,count: expectlen)
- let readLen:Int32=c_ytcpsocket_pull(fd, buff: &buff, len: Int32(expectlen), timeout: Int32(timeout))
- if readLen<=0{
- return nil
- }
- let rs=buff[0...Int(readLen-1)]
- let data:[UInt8] = Array(rs)
- return data
- }
- return nil
- }
-}
-
-open class TCPServer:YSocket{
-
- open func listen()->(Bool,String){
-
- let fd:Int32=c_ytcpsocket_listen(self.addr, port: Int32(self.port))
- if fd>0{
- self.fd=fd
- return (true,"listen success")
- }else{
- return (false,"listen fail")
- }
- }
- open func accept()->TCPClient?{
- if let serferfd=self.fd{
- var buff:[Int8] = [Int8](repeating: 0x0,count: 16)
- var port:Int32=0
- let clientfd:Int32=c_ytcpsocket_accept(serferfd, ip: &buff,port: &port)
- if clientfd<0{
- return nil
- }
- let tcpClient:TCPClient=TCPClient()
- tcpClient.fd=clientfd
- tcpClient.port=Int(port)
- if let addr=String(cString: buff, encoding: String.Encoding.utf8){
- tcpClient.addr=addr
- }
- return tcpClient
- }
- return nil
- }
- open func close()->(Bool,String){
- if let fd:Int32=self.fd{
- c_ytcpsocket_close(fd)
- self.fd=nil
- return (true,"close success")
- }else{
- return (false,"socket not open")
- }
- }
-}
-
-
diff --git a/SwiftSocket/ysocket/yudpsocket.c b/SwiftSocket/ysocket/yudpsocket.c
deleted file mode 100644
index a03c0c5..0000000
--- a/SwiftSocket/ysocket/yudpsocket.c
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- Copyright (c) <2014>, skysent
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
- 3. All advertising materials mentioning features or use of this software
- must display the following acknowledgement:
- This product includes software developed by skysent.
- 4. Neither the name of the skysent nor the
- names of its contributors may be used to endorse or promote products
- derived from this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY skysent ''AS IS'' AND ANY
- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- DISCLAIMED. IN NO EVENT SHALL skysent BE LIABLE FOR ANY
- DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#define yudpsocket_buff_len 8192
-
-//return socket fd
-int yudpsocket_server(const char *addr,int port){
- //create socket
- int socketfd=socket(AF_INET, SOCK_DGRAM, 0);
- int reuseon = 1;
- int r = -1;
- //bind
- struct sockaddr_in serv_addr;
- serv_addr.sin_len = sizeof(struct sockaddr_in);
- serv_addr.sin_family = AF_INET;
- if(addr == NULL || strlen(addr) == 0 || strcmp(addr, "255.255.255.255") == 0)
- {
- r = setsockopt( socketfd, SOL_SOCKET, SO_BROADCAST, &reuseon, sizeof(reuseon) );
- serv_addr.sin_port = htons(port);
- serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
- }else{
- r = setsockopt( socketfd, SOL_SOCKET, SO_REUSEADDR, &reuseon, sizeof(reuseon) );
- serv_addr.sin_addr.s_addr = inet_addr(addr);
- serv_addr.sin_port = htons(port);
- memset( &serv_addr, '\0', sizeof(serv_addr));
- }
- if(r==-1){
- return -1;
- }
- r=bind(socketfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr));
- if(r==0){
- return socketfd;
- }else{
- return -1;
- }
-}
-int yudpsocket_recive(int socket_fd,char *outdata,int expted_len,char *remoteip,int* remoteport){
- struct sockaddr_in cli_addr;
- socklen_t clilen=sizeof(cli_addr);
- memset(&cli_addr, 0x0, sizeof(struct sockaddr_in));
- int len=(int)recvfrom(socket_fd, outdata, expted_len, 0, (struct sockaddr *)&cli_addr, &clilen);
- char *clientip=inet_ntoa(cli_addr.sin_addr);
- memcpy(remoteip, clientip, strlen(clientip));
- *remoteport=cli_addr.sin_port;
- return len;
-}
-int yudpsocket_close(int socket_fd){
- return close(socket_fd);
-}
-//return socket fd
-int yudpsocket_client(){
- //create socket
- int socketfd=socket(AF_INET, SOCK_DGRAM, 0);
- int reuseon = 1;
- setsockopt( socketfd, SOL_SOCKET, SO_REUSEADDR, &reuseon, sizeof(reuseon) );
- return socketfd;
-}
-//enable broadcast
-void enable_broadcast(int socket_fd){
- int reuseon = 1;
- setsockopt( socket_fd, SOL_SOCKET, SO_BROADCAST, &reuseon, sizeof(reuseon) );
-}
-int yudpsocket_get_server_ip(char *host,char *ip){
- struct hostent *hp;
- struct sockaddr_in addr;
- hp = gethostbyname(host);
- if(hp==NULL){
- return -1;
- }
- bcopy((char *)hp->h_addr, (char *)&addr.sin_addr, hp->h_length);
- char *clientip=inet_ntoa(addr.sin_addr);
- memcpy(ip, clientip, strlen(clientip));
- return 0;
-}
-//send message to addr and port
-int yudpsocket_sentto(int socket_fd,char *msg,int len, char *toaddr, int topotr){
- struct sockaddr_in addr;
- socklen_t addrlen=sizeof(addr);
- memset(&addr, 0x0, sizeof(struct sockaddr_in));
- addr.sin_family=AF_INET;
- addr.sin_port=htons(topotr);
- addr.sin_addr.s_addr=inet_addr(toaddr);
- int sendlen=(int)sendto(socket_fd, msg, len, 0, (struct sockaddr *)&addr, addrlen);
- return sendlen;
-}
-
-
diff --git a/SwiftSocket/ysocket/yudpsocket.swift b/SwiftSocket/ysocket/yudpsocket.swift
deleted file mode 100644
index c5f9bbd..0000000
--- a/SwiftSocket/ysocket/yudpsocket.swift
+++ /dev/null
@@ -1,166 +0,0 @@
-/*
-Copyright (c) <2014>, skysent
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-1. Redistributions of source code must retain the above copyright
-notice, this list of conditions and the following disclaimer.
-2. Redistributions in binary form must reproduce the above copyright
-notice, this list of conditions and the following disclaimer in the
-documentation and/or other materials provided with the distribution.
-3. All advertising materials mentioning features or use of this software
-must display the following acknowledgement:
-This product includes software developed by skysent.
-4. Neither the name of the skysent nor the
-names of its contributors may be used to endorse or promote products
-derived from this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY skysent ''AS IS'' AND ANY
-EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-DISCLAIMED. IN NO EVENT SHALL skysent BE LIABLE FOR ANY
-DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-import Foundation
-
-@_silgen_name("yudpsocket_server") func c_yudpsocket_server(_ host:UnsafePointer,port:Int32) -> Int32
-@_silgen_name("yudpsocket_recive") func c_yudpsocket_recive(_ fd:Int32,buff:UnsafePointer,len:Int32,ip:UnsafePointer,port:UnsafePointer) -> Int32
-@_silgen_name("yudpsocket_close") func c_yudpsocket_close(_ fd:Int32) -> Int32
-@_silgen_name("yudpsocket_client") func c_yudpsocket_client() -> Int32
-@_silgen_name("yudpsocket_get_server_ip") func c_yudpsocket_get_server_ip(_ host:UnsafePointer,ip:UnsafePointer) -> Int32
-@_silgen_name("yudpsocket_sentto") func c_yudpsocket_sentto(_ fd:Int32,buff:UnsafePointer,len:Int32,ip:UnsafePointer,port:Int32) -> Int32
-@_silgen_name("enable_broadcast") func c_enable_broadcast(_ fd:Int32)
-
-open class UDPClient: YSocket {
- public override init(addr a:String,port p:Int){
- super.init()
- let remoteipbuff:[Int8] = [Int8](repeating: 0x0,count: 16)
- let ret=c_yudpsocket_get_server_ip(a, ip: remoteipbuff)
- if ret==0{
- if let ip=String(cString: remoteipbuff, encoding: String.Encoding.utf8){
- self.addr=ip
- self.port=p
- let fd:Int32=c_yudpsocket_client()
- if fd>0{
- self.fd=fd
- }
- }
- }
- }
- /*
- * send data
- * return success or fail with message
- */
- open func send(data d:[UInt8])->(Bool,String){
- if let fd:Int32=self.fd{
- let sendsize:Int32=c_yudpsocket_sentto(fd, buff: d, len: Int32(d.count), ip: self.addr,port: Int32(self.port))
- if Int(sendsize)==d.count{
- return (true,"send success")
- }else{
- return (false,"send error")
- }
- }else{
- return (false,"socket not open")
- }
- }
- /*
- * send string
- * return success or fail with message
- */
- open func send(str s:String)->(Bool,String){
- if let fd:Int32=self.fd{
- let sendsize:Int32=c_yudpsocket_sentto(fd, buff: s, len: Int32(strlen(s)), ip: self.addr,port: Int32(self.port))
- if sendsize==Int32(strlen(s)){
- return (true,"send success")
- }else{
- return (false,"send error")
- }
- }else{
- return (false,"socket not open")
- }
- }
- /*
- * enableBroadcast
- */
- open func enableBroadcast(){
- if let fd:Int32=self.fd{
- c_enable_broadcast(fd)
-
- }
- }
- /*
- *
- * send nsdata
- */
- open func send(data d:Data)->(Bool,String){
- if let fd:Int32=self.fd{
- var buff:[UInt8] = [UInt8](repeating: 0x0,count: d.count)
- (d as NSData).getBytes(&buff, length: d.count)
- let sendsize:Int32=c_yudpsocket_sentto(fd, buff: buff, len: Int32(d.count), ip: self.addr,port: Int32(self.port))
- if sendsize==Int32(d.count){
- return (true,"send success")
- }else{
- return (false,"send error")
- }
- }else{
- return (false,"socket not open")
- }
- }
- open func close()->(Bool,String){
- if let fd:Int32=self.fd{
- c_yudpsocket_close(fd)
- self.fd=nil
- return (true,"close success")
- }else{
- return (false,"socket not open")
- }
- }
- //TODO add multycast and boardcast
-}
-
-open class UDPServer:YSocket{
- public override init(addr a:String,port p:Int){
- super.init(addr: a, port: p)
- let fd:Int32 = c_yudpsocket_server(self.addr, port: Int32(self.port))
- if fd>0{
- self.fd=fd
- }
- }
- //TODO add multycast and boardcast
- open func recv(_ expectlen:Int)->([UInt8]?,String,Int){
- if let fd:Int32 = self.fd{
- var buff:[UInt8] = [UInt8](repeating: 0x0,count: expectlen)
- var remoteipbuff:[Int8] = [Int8](repeating: 0x0,count: 16)
- var remoteport:Int32=0
- let readLen:Int32=c_yudpsocket_recive(fd, buff: buff, len: Int32(expectlen), ip: &remoteipbuff, port: &remoteport)
- let port:Int=Int(remoteport)
- var addr:String=""
- if let ip=String(cString: remoteipbuff, encoding: String.Encoding.utf8){
- addr=ip
- }
- if readLen<=0{
- return (nil,addr,port)
- }
- let rs=buff[0...Int(readLen-1)]
- let data:[UInt8] = Array(rs)
- return (data,addr,port)
- }
- return (nil,"no ip",0)
- }
- open func close()->(Bool,String){
- if let fd:Int32=self.fd{
- c_yudpsocket_close(fd)
- self.fd=nil
- return (true,"close success")
- }else{
- return (false,"socket not open")
- }
- }
-}
diff --git a/iOS Example/AppDelegate.swift b/iOS Example/AppDelegate.swift
new file mode 100644
index 0000000..aef5fe6
--- /dev/null
+++ b/iOS Example/AppDelegate.swift
@@ -0,0 +1,22 @@
+//
+// AppDelegate.swift
+// iOS Example
+//
+// Created by Dan Shevlyuk on 11/16/16.
+// Copyright © 2016 swift. All rights reserved.
+//
+
+import UIKit
+
+@UIApplicationMain
+class AppDelegate: UIResponder, UIApplicationDelegate {
+
+ var window: UIWindow?
+
+
+ func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
+ return true
+ }
+
+}
+
diff --git a/iOS Example/Assets.xcassets/AppIcon.appiconset/Contents.json b/iOS Example/Assets.xcassets/AppIcon.appiconset/Contents.json
new file mode 100644
index 0000000..36d2c80
--- /dev/null
+++ b/iOS Example/Assets.xcassets/AppIcon.appiconset/Contents.json
@@ -0,0 +1,68 @@
+{
+ "images" : [
+ {
+ "idiom" : "iphone",
+ "size" : "29x29",
+ "scale" : "2x"
+ },
+ {
+ "idiom" : "iphone",
+ "size" : "29x29",
+ "scale" : "3x"
+ },
+ {
+ "idiom" : "iphone",
+ "size" : "40x40",
+ "scale" : "2x"
+ },
+ {
+ "idiom" : "iphone",
+ "size" : "40x40",
+ "scale" : "3x"
+ },
+ {
+ "idiom" : "iphone",
+ "size" : "60x60",
+ "scale" : "2x"
+ },
+ {
+ "idiom" : "iphone",
+ "size" : "60x60",
+ "scale" : "3x"
+ },
+ {
+ "idiom" : "ipad",
+ "size" : "29x29",
+ "scale" : "1x"
+ },
+ {
+ "idiom" : "ipad",
+ "size" : "29x29",
+ "scale" : "2x"
+ },
+ {
+ "idiom" : "ipad",
+ "size" : "40x40",
+ "scale" : "1x"
+ },
+ {
+ "idiom" : "ipad",
+ "size" : "40x40",
+ "scale" : "2x"
+ },
+ {
+ "idiom" : "ipad",
+ "size" : "76x76",
+ "scale" : "1x"
+ },
+ {
+ "idiom" : "ipad",
+ "size" : "76x76",
+ "scale" : "2x"
+ }
+ ],
+ "info" : {
+ "version" : 1,
+ "author" : "xcode"
+ }
+}
\ No newline at end of file
diff --git a/iOS Example/Base.lproj/LaunchScreen.storyboard b/iOS Example/Base.lproj/LaunchScreen.storyboard
new file mode 100644
index 0000000..fdf3f97
--- /dev/null
+++ b/iOS Example/Base.lproj/LaunchScreen.storyboard
@@ -0,0 +1,27 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/iOS Example/Base.lproj/Main.storyboard b/iOS Example/Base.lproj/Main.storyboard
new file mode 100644
index 0000000..f3d0376
--- /dev/null
+++ b/iOS Example/Base.lproj/Main.storyboard
@@ -0,0 +1,61 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/iOS Example/Info.plist b/iOS Example/Info.plist
new file mode 100644
index 0000000..d052473
--- /dev/null
+++ b/iOS Example/Info.plist
@@ -0,0 +1,45 @@
+
+
+
+
+ CFBundleDevelopmentRegion
+ en
+ CFBundleExecutable
+ $(EXECUTABLE_NAME)
+ CFBundleIdentifier
+ $(PRODUCT_BUNDLE_IDENTIFIER)
+ CFBundleInfoDictionaryVersion
+ 6.0
+ CFBundleName
+ $(PRODUCT_NAME)
+ CFBundlePackageType
+ APPL
+ CFBundleShortVersionString
+ 1.0
+ CFBundleVersion
+ 1
+ LSRequiresIPhoneOS
+
+ UILaunchStoryboardName
+ LaunchScreen
+ UIMainStoryboardFile
+ Main
+ UIRequiredDeviceCapabilities
+
+ armv7
+
+ UISupportedInterfaceOrientations
+
+ UIInterfaceOrientationPortrait
+ UIInterfaceOrientationLandscapeLeft
+ UIInterfaceOrientationLandscapeRight
+
+ UISupportedInterfaceOrientations~ipad
+
+ UIInterfaceOrientationPortrait
+ UIInterfaceOrientationPortraitUpsideDown
+ UIInterfaceOrientationLandscapeLeft
+ UIInterfaceOrientationLandscapeRight
+
+
+
diff --git a/iOS Example/ViewController.swift b/iOS Example/ViewController.swift
new file mode 100644
index 0000000..1d3c948
--- /dev/null
+++ b/iOS Example/ViewController.swift
@@ -0,0 +1,55 @@
+import UIKit
+import SwiftSocket
+
+class ViewController: UIViewController {
+
+ @IBOutlet weak var textView: UITextView!
+
+ let host = "apple.com"
+ let port = 80
+ var client: TCPClient?
+
+ override func viewDidLoad() {
+ super.viewDidLoad()
+
+ client = TCPClient(address: host, port: Int32(port))
+ }
+
+ @IBAction func sendButtonAction() {
+ guard let client = client else { return }
+
+ switch client.connect(timeout: 10) {
+ case .success:
+ appendToTextField(string: "Connected to host \(client.address)")
+ if let response = sendRequest(string: "GET / HTTP/1.0\n\n", using: client) {
+ appendToTextField(string: "Response: \(response)")
+ }
+ case .failure(let error):
+ appendToTextField(string: String(describing: error))
+ }
+ }
+
+ private func sendRequest(string: String, using client: TCPClient) -> String? {
+ appendToTextField(string: "Sending data ... ")
+
+ switch client.send(string: string) {
+ case .success:
+ return readResponse(from: client)
+ case .failure(let error):
+ appendToTextField(string: String(describing: error))
+ return nil
+ }
+ }
+
+ private func readResponse(from client: TCPClient) -> String? {
+ guard let response = client.read(1024*10) else { return nil }
+
+ return String(bytes: response, encoding: .utf8)
+ }
+
+ private func appendToTextField(string: String) {
+ print(string)
+ textView.text = textView.text.appending("\n\(string)")
+ }
+
+}
diff --git a/license b/license
index 732a7b0..2bea3fb 100644
--- a/license
+++ b/license
@@ -1,4 +1,3 @@
-/*
Copyright (c) <2014>, skysent
All rights reserved.
@@ -26,4 +25,3 @@ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*
\ No newline at end of file
diff --git a/ysocket-ios/ysocket-ios.h b/ysocket-ios/ysocket-ios.h
deleted file mode 100644
index 30910a0..0000000
--- a/ysocket-ios/ysocket-ios.h
+++ /dev/null
@@ -1,19 +0,0 @@
-//
-// ysocket-ios.h
-// ysocket-ios
-//
-// Created by 彭运筹 on 15/1/2.
-// Copyright (c) 2015年 swift. All rights reserved.
-//
-
-#import
-
-//! Project version number for ysocket-ios.
-FOUNDATION_EXPORT double ysocket_iosVersionNumber;
-
-//! Project version string for ysocket-ios.
-FOUNDATION_EXPORT const unsigned char ysocket_iosVersionString[];
-
-// In this header, you should import all the public headers of your framework using statements like #import
-
-
diff --git a/ysocketOSX/Info.plist b/ysocketOSX/Info.plist
deleted file mode 100644
index 5018406..0000000
--- a/ysocketOSX/Info.plist
+++ /dev/null
@@ -1,28 +0,0 @@
-
-
-
-
- CFBundleDevelopmentRegion
- en
- CFBundleExecutable
- $(EXECUTABLE_NAME)
- CFBundleIdentifier
- $(PRODUCT_BUNDLE_IDENTIFIER)
- CFBundleInfoDictionaryVersion
- 6.0
- CFBundleName
- $(PRODUCT_NAME)
- CFBundlePackageType
- FMWK
- CFBundleShortVersionString
- 1.0
- CFBundleSignature
- ????
- CFBundleVersion
- $(CURRENT_PROJECT_VERSION)
- NSHumanReadableCopyright
- Copyright © 2015年 swift. All rights reserved.
- NSPrincipalClass
-
-
-
diff --git a/ysocketOSX/ysocketOSX.h b/ysocketOSX/ysocketOSX.h
deleted file mode 100644
index 546fa45..0000000
--- a/ysocketOSX/ysocketOSX.h
+++ /dev/null
@@ -1,19 +0,0 @@
-//
-// ysocketOSX.h
-// ysocketOSX
-//
-// Created by 彭运筹 on 15/1/2.
-// Copyright (c) 2015年 swift. All rights reserved.
-//
-
-#import
-
-//! Project version number for ysocketOSX.
-FOUNDATION_EXPORT double ysocketOSXVersionNumber;
-
-//! Project version string for ysocketOSX.
-FOUNDATION_EXPORT const unsigned char ysocketOSXVersionString[];
-
-// In this header, you should import all the public headers of your framework using statements like #import
-
-