diff --git a/Source/Extensions/NSURL+TrailingSlash.swift b/Source/Extensions/NSURL+TrailingSlash.swift index 641407a..662b071 100644 --- a/Source/Extensions/NSURL+TrailingSlash.swift +++ b/Source/Extensions/NSURL+TrailingSlash.swift @@ -38,7 +38,12 @@ internal extension NSURL { } var relativeURL: NSURL? { - return NSURL(string: "\(self.scheme!)://\(self.host!):\(self.port!)") + if let port = self.port { + return NSURL(string: "\(self.scheme!)://\(self.host!):\(port)") + } + else { + return NSURL(string: "\(self.scheme!)://\(self.host!)") + } } } diff --git a/Source/SocketIOWebSocket.swift b/Source/SocketIOWebSocket.swift index 8da42e6..c39f2bb 100644 --- a/Source/SocketIOWebSocket.swift +++ b/Source/SocketIOWebSocket.swift @@ -11,6 +11,7 @@ import Foundation class SocketIOWebSocket: SocketIOTransport, WebSocketDelegate { private var socket: WebSocket! + private let defaultPort = 80 private var nsp: String { return delegate.options.namespace @@ -26,7 +27,16 @@ class SocketIOWebSocket: SocketIOTransport, WebSocketDelegate { return } - if let scheme = hostUrl.scheme, let host = hostUrl.host, let port = hostUrl.port { + // Check current port + let port: Int + if let hostPort = hostUrl.port { + port = hostPort.integerValue + } + else { + port = defaultPort + } + + if let scheme = hostUrl.scheme, let host = hostUrl.host { // Establish connection if scheme.lowercaseString == "http" { // Standard