Skip to content

Commit

Permalink
minor updates
Browse files Browse the repository at this point in the history
- updated to conform the latest specification of JSTP
- added ability to reconnect
  • Loading branch information
Gagnant committed Nov 26, 2016
1 parent 1ea9ddd commit cb0b55d
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1 +1 @@
github "Gagnant/Socket" "0.1.4"
github "Gagnant/Socket" "0.1.6"
2 changes: 1 addition & 1 deletion JSTP.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = 'JSTP'
s.version = '0.1.8'
s.version = '0.1.9'
s.license = { :type => "MIT" }

s.homepage = 'https://github.com/metarhia/JSTP'
Expand Down
7 changes: 4 additions & 3 deletions JSTP/Chunks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ internal class Chunks {
return nil
}

let chunks = buffer + kChunksLast
var chunks = buffer + kChunksLast
buffer = kChunksFirst


chunks = chunks.replacingOccurrences(of: kPacketDelimiter, with: ",")

let packets = Context.shared.parse(chunks)

guard packets.isUndefined == false,
Expand All @@ -39,4 +41,3 @@ internal class Chunks {
}

}

2 changes: 1 addition & 1 deletion JSTP/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Copyright © 2016 Andrew Visotskyy. All rights reserved.
//

internal let kPacketDelimiter = ",{\u{C}},"
internal let kPacketDelimiter = "\u{0}"
internal let kPacketDelimiterLength = kPacketDelimiter.characters.count
internal let kChunksFirst = "["
internal let kChunksLast = "]"
Expand Down
30 changes: 28 additions & 2 deletions JSTP/Initializers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ public extension Connection {
}

let socket = TCPSocket (host: host, port: port, settings: settings)

self.init(socket: socket)
}

public convenience init? (url: String, secure: Bool = true) {

guard let url = URL(string: url) else {
return nil
}
Expand All @@ -46,5 +46,31 @@ public extension Connection {
self.socket.connect()
}

public func reconnect() {

let secure = socket.options.contains { SocketSecurityLevel == $0 &&
SocketSecurityLevelNone == $1 as! String }

self.reconnect(host: socket.host, port: socket.port, secure: secure)
}

public func reconnect(host: String, port: Int, secure: Bool = true) {

var settings = Settings()

if secure == false {
settings[SocketSecurityLevel] = SocketSecurityLevelNone
}

self.callbacks = Callbacks()
self.chunks = Chunks()
self.packetId = 0

self.socket = TCPSocket(host: host, port: port, settings: settings)

self.socket.delegate = TCPSocketDelegateImplementation(self)
self.socket.connect()
}

}

0 comments on commit cb0b55d

Please sign in to comment.