Socket.IO - Socket.IO client for iOS/OS X.

Overview

Build Status

Socket.IO-Client-Swift

Socket.IO-client for iOS/OS X.

Example

import SocketIO

let manager = SocketManager(socketURL: URL(string: "http://localhost:8080")!, config: [.log(true), .compress])
let socket = manager.defaultSocket

socket.on(clientEvent: .connect) {data, ack in
    print("socket connected")
}

socket.on("currentAmount") {data, ack in
    guard let cur = data[0] as? Double else { return }
    
    socket.emitWithAck("canUpdate", cur).timingOut(after: 0) {data in
        if data.first as? String ?? "passed" == SocketAckValue.noAck {
            // Handle ack timeout 
        }

        socket.emit("update", ["amount": cur + 2.50])
    }

    ack.with("Got your currentAmount", "dude")
}

socket.connect()

Features

  • Supports socket.io 2.0+/3.0+.
  • Supports Binary
  • Supports Polling and WebSockets
  • Supports TLS/SSL

FAQS

Checkout the FAQs for commonly asked questions.

Checkout the 12to13 guide for migrating to v13+ from v12 below.

Checkout the 15to16 guide for migrating to v16+ from v15.

Installation

Requires Swift 4/5 and Xcode 10.x

Swift Package Manager

Add the project as a dependency to your Package.swift:

// swift-tools-version:4.2

import PackageDescription

let package = Package(
    name: "socket.io-test",
    products: [
        .executable(name: "socket.io-test", targets: ["YourTargetName"])
    ],
    dependencies: [
        .package(url: "https://github.com/socketio/socket.io-client-swift", .upToNextMinor(from: "15.0.0"))
    ],
    targets: [
        .target(name: "YourTargetName", dependencies: ["SocketIO"], path: "./Path/To/Your/Sources")
    ]
)

Then import import SocketIO.

Carthage

Add this line to your Cartfile:

15.2.0 ">
github "socketio/socket.io-client-swift" ~> 15.2.0

Run carthage update --platform ios,macosx.

Add the Starscream and SocketIO frameworks to your projects and follow the usual Carthage process.

CocoaPods 1.0.0 or later

Create Podfile and add pod 'Socket.IO-Client-Swift':

use_frameworks!

target 'YourApp' do
    pod 'Socket.IO-Client-Swift', '~> 15.2.0'
end

Install pods:

$ pod install

Import the module:

Swift:

import SocketIO

Objective-C:

@import SocketIO;

Docs

Detailed Example

A more detailed example can be found here

An example using the Swift Package Manager can be found here

License

MIT

Comments
  • xcode 8 errors

    xcode 8 errors

    I just tried building my app using xcode 8 and got multiple erros in socket.io client. Is there something I can do to build, or do I just need to wait? screen shot 2016-07-27 at 14 51 36

    in progress 
    opened by acMaia 54
  • Could not build module 'SocketIO'

    Could not build module 'SocketIO'

    What i did

    • Remove all pod files and reinstall
    • Added pod 'Socket.IO-Client-Swift', '~> 10.0.1’
    • Removed derived data
    • Clean the project screen shot 2017-06-22 at 12 29 12 pm

    screen shot 2017-06-22 at 12 25 47 pm

    I got these Error Xcode 8.3.3 COCOAPODS UPDATED TO LATEST VIRSION

    bug unconfirmed 
    opened by chirag225 48
  • disconnect event fired before server recognizes disconnect

    disconnect event fired before server recognizes disconnect

    Sometimes when I call disconnect on the client the socket is immediately disconnected on the server. Other times it seems to take ~30 seconds. Is there anyway to make this consistent?

    opened by 2fours 44
  • [ERROR] SocketIOClient: Invalid HTTP upgrade

    [ERROR] SocketIOClient: Invalid HTTP upgrade

    Hi,

    I'm facing an issue that I don't understand and I need help. With the new version of the client I have random connection problem which display these logs:

    Log SocketIOClient: Adding handler for event: disconnect
    Log SocketIOClient: Adding handler for event: error
    Log SocketIOClient: Adding engine
    Log SocketEngine: Starting engine
    Log SocketEngine: Handshaking
    ERROR SocketIOClient: Invalid HTTP upgrade
    Log SocketIOClient: Handling event: error with data: (
        "Invalid HTTP upgrade"
    )
    Log SocketIOClient: Disconnected: Invalid HTTP upgrade
    Log SocketEngine: Engine is being closed. Fast: 1
    Log SocketIOClient: Handling event: disconnect with data: (
        "Invalid HTTP upgrade"
    )
    Log SocketEngine: Got message: 40
    Log SocketParser: Parsing 0
    Log SocketParser: Decoded packet as: SocketPacket {type: 0; data: []; id: -1; placeholders: 0; nsp: /}
    Log SocketIOClient: Socket connected
    Log SocketIOClient: Handling event: connect with data: 
    Got event: connect, with items: nil
    Log SocketIOClient: Client is being deinit
    Log SocketEngine: Engine is being closed. Fast: 1
    Log SocketEngine: Engine is being deinit
    

    On the server (node.js 4.1.0, socket.io 1.3.7) I have a "handshake" and a connection event. It happens on iOS 8.x and 9.x (iPads). With the previous version and swift 1.x everything worked well, but now it randomly failed. Have you some ideas?

    bug patched 
    opened by yannickl 37
  • Tests for socket.io client

    Tests for socket.io client

    I really like your project and want to try to contribute to it. But before contributing with confidence I think it is a good start to write some tests.

    I started writing tests. I wrote a little test server I plan to run the server on a free tier on heroku and use Travis when it supports Xcode 7.x. The setup brings continuous integration for free.

    By cloning the server repository everyone can run it locally.

    I hope you like the idea of building up a set of tests to verify the socket.io client.

    opened by lightsprint09 37
  • SocketIO Client not working with namespace

    SocketIO Client not working with namespace

    Hi, I've a problem to make my iOS app work with SocketIO namespaces. I have a NodeJS server with SocketIO 2.0.3 and a namespace "/user". On Android everything works good but on iOS it doesn't connect. I'm using the socket.io-client-swift version 10.2.0 I put the log on and here what I get: 2017-07-12 11:02:50.716 Ellistra[5373:65271] LOG SocketIOClient: Handling event: statusChange with data: [SocketIO.SocketIOClientStatus] 2017-07-12 11:02:50.716 Ellistra[5373:65271] LOG SocketIOClient: Adding engine 2017-07-12 11:02:50.718 Ellistra[5373:65358] LOG SocketEngine: Starting engine. Server: http://192.168.2.114 2017-07-12 11:02:50.718 Ellistra[5373:65358] LOG SocketEngine: Handshaking 2017-07-12 11:02:50.952 Ellistra[5373:65360] LOG SocketEngine: Got message: 0{"sid":"Btz7E9OP_NKfwL3IAAAA","upgrades":[],"pingInterval":25000,"pingTimeout":60000} 2017-07-12 11:02:50.953 Ellistra[5373:65360] LOG SocketEngineClient: Connect 2017-07-12 11:02:50.953 Ellistra[5373:65360] LOG SocketEngine: Writing ws: has data: false 2017-07-12 11:02:50.954 Ellistra[5373:65360] LOG SocketEngine: Sending ws: as type: 2 2017-07-12 11:02:50.977 Ellistra[5373:65360] LOG SocketEngine: Got message: 3 2017-07-12 11:03:15.954 Ellistra[5373:65354] LOG SocketEngine: Writing ws: has data: false 2017-07-12 11:03:15.954 Ellistra[5373:65354] LOG SocketEngine: Sending ws: as type: 2 2017-07-12 11:03:15.992 Ellistra[5373:65354] LOG SocketEngine: Got message: 3 2017-07-12 11:03:40.955 Ellistra[5373:65894] LOG SocketEngine: Writing ws: has data: false 2017-07-12 11:03:40.956 Ellistra[5373:65894] LOG SocketEngine: Sending ws: as type: 2 2017-07-12 11:03:45.218 Ellistra[5373:65894] LOG SocketEngine: Got message: 3

    I get that indefinitely. Here is how I create my socket: let params: [String: String] = ["token": EllistraSettings.sharedInstance.accessToken!] let config: SocketIOClientConfiguration = [.log(true), .forceWebsockets(true), .connectParams(params), .secure(false), .nsp("/user")] socket = SocketIOClient(socketURL: URL(string: "http://192.168.2.114")!, config: config) // Different SocketIO events, onConnect, onDisconnect, onMessageReceived... socket?.on(...) socket?.connect()

    But I never get .connect SocketIO event. Thanks for your help, JB

    bug patched 
    opened by jbmolle 33
  • How to import Starscream when I use the BridgingHeader to add SocketIOClient version 11.

    How to import Starscream when I use the BridgingHeader to add SocketIOClient version 11.

    At the first I'm using previous version before 11 (swift 2.3) in xcode 8.2.1 in OS X EL Capitan. But now I have to upgrade OS Sierra and use xcode 8.3.3 for some projects. Then I also need to upgrade the swift version for current socketIO-client to swift3. But current project is written in objective-c. So Im using the bridging header file to manually add the socketIO.

    But I got some problems to use the latest version of socketIO-client (version11) because it had a dependency called Starscream and I could not add that manually to my project using bridging header. Could you please help me to add Starscream manually to the project using bridging header. Regards and thanks.

    opened by NyeinEiEiTun 30
  • Carthage Support

    Carthage Support

    • Added support for building the framework using Carthage.
    • Renamed the SwiftIO directory to SocketIO for consistency.
    • Includes OS X support, I didn't dive into the code to see if there's anything platform dependent, but skimming through it looked OK.
    • Updated the README for carthage installation directions.
    • The pod spec should probably be reviewed, as I'm not a user of cocoapods, but it should be correct.

    This does NOT include any of the updates for Swift 1.2, and should be merged in before any of those changes are made.

    opened by justinmakaila 30
  • swift ios使用可能存在漏接收数据的情况,应该怎么处理?

    swift ios使用可能存在漏接收数据的情况,应该怎么处理?

    My project is swift,xcode8.3,swift3.1 。 I felt as if there is leakage of data, because the android there can be the received data, I here can only receive a part of, and I see in the Log output that has that part did not receive the data, but in on (" data ") {(data, ack)} in the callback method that part did not receive the data。 I don't know if anyone has encountered similar problems. What's the solution? Thank you!

    我觉得好像有漏接数据的情况,因为android可以接收到的数据在我这里(ios)只能接收的一部分,但是我在日志输出的数据里面有看到我没有接收到的那部分数据,但是在on (" data ") {(data, ack)} 的回调方法中却没有接收到 。 不知道有没有人遇到过类似的问题,请问有什么解决思路提供,谢谢!

    invalid 
    opened by JoyGY 29
  • About nil sid in

    About nil sid in "connect" event callback

    in "connect" event callback, sid of SocketIOClient may be nil in some circumstance. I'm not sure if that's a bug caused by some race conditions or it's designed to work that way. Any information would be appreciated. Thanks.

    bug patched 
    opened by hankbao 28
  • Socket emit event from client but it never reaches to server

    Socket emit event from client but it never reaches to server

    I am using socket.io v.15.2.0, sometimes socket connect successfully but when client emit the event it never reaches to server

    following is my code to emit the event after successful connection

     // Intialize socket
    self.socket = SocketHelper.shared().getSocketWithLazyConnect()
            
    // Connect Event
    self.socket?.off("connect")
    self.socket?.on("connect", callback: { (data, ack) in
    
    self.socket?.emit(Constants.SocketEvent.loadConversations)
    
    })
    

    Following is my socket helper class

    import UIKit
    import SocketIO
    
    class SocketHelper {
    
        //static let shared = SocketHelper()
        private static var privateShared : SocketHelper?
        var socket: SocketIOClient!
    
        var delegate: SocketHelperDelegate?
        
        let manager = SocketManager(socketURL: URL(string: ApiUrls.socketUrl)!, config: [.log(true), .compress, .connectParams(["token": Globals.shared.session.accessToken]), .secure(true), .forceWebsockets(true), .forcePolling(false)])
        
        
        private init() {
            self.socket = self.manager.defaultSocket
            self.addEventHandlers()
        }
        
        class func shared() -> SocketHelper { // change class to final to prevent override
            guard let uwShared = privateShared else {
                privateShared = SocketHelper()
                return privateShared!
            }
            return uwShared
        }
        
        func getSocketWithLazyConnect() -> SocketIOClient {
            if self.socket.status == .connected {
                return self.socket
            }
            self.manager.reconnects = true
            self.manager.connectSocket(self.socket)
            
            return self.socket
        }
        
        func disconnect() {
            self.manager.reconnects = false
            self.manager.disconnectSocket(self.socket)
        }
        
        func isConnected() -> Bool {
            return self.socket.status == .connected
        }
        
        func destroy() {
            SocketHelper.privateShared = nil
        }
        
        func addEventHandlers() {
            // Connect Event
            self.socket.off("connect")
            self.socket.on("connect", callback: { (data, ack) in
    
                self.delegate?.onSocketConnected(data: data)
                
            })
            
            // Load Conversations Event
            self.socket.off(Constants.SocketEvent.loadConversations)
            self.socket.on(Constants.SocketEvent.loadConversations, callback: { (data, ack) in
                
                self.delegate?.onLoadConversationEventResponse(data: data)
                
            })
            
            
        }
    }
    

    In logs it shows that loadConversation event is emitted from client but when debugged same time on server, event didn't received by server.

    following is my log

    2020-12-03 14:24:39.765561+0530 Capshot[27105:8609477] LOG SocketEngine: Writing ws: 1/, has data: false
    2020-12-03 14:24:39.765901+0530 Capshot[27105:8609477] LOG SocketEngineWebSocket: Sending ws: 1/, as type: 4
    2020-12-03 14:24:41.506539+0530 Capshot[27105:8609466] LOG SocketEngine: Writing ws:  has data: false
    2020-12-03 14:24:41.507240+0530 Capshot[27105:8609238] LOG SocketIOClient{/}: Handling event: ping with data: []
    2020-12-03 14:24:41.507255+0530 Capshot[27105:8609466] LOG SocketEngineWebSocket: Sending ws:  as type: 2
    2020-12-03 14:24:41.523075+0530 Capshot[27105:8609477] LOG SocketEngine: Got message: 3
    2020-12-03 14:24:41.523808+0530 Capshot[27105:8609238] LOG SocketIOClient{/}: Handling event: pong with data: []
    2020-12-03 14:24:42.569332+0530 Capshot[27105:8609238] LOG SocketIOClient{/}: Removing handler for event: connect
    2020-12-03 14:24:42.569346+0530 Capshot[27105:8609466] LOG SocketEngine: Writing ws: 0/, has data: false
    2020-12-03 14:24:42.569654+0530 Capshot[27105:8609466] LOG SocketEngineWebSocket: Sending ws: 0/, as type: 4
    2020-12-03 14:24:42.569725+0530 Capshot[27105:8609238] LOG SocketIOClient{/}: Adding handler for event: connect
    2020-12-03 14:24:42.569922+0530 Capshot[27105:8609238] LOG SocketIOClient{/}: Removing handler for event: loadConversations
    2020-12-03 14:24:42.570121+0530 Capshot[27105:8609238] LOG SocketIOClient{/}: Adding handler for event: loadConversations
    2020-12-03 14:24:42.570283+0530 Capshot[27105:8609238] LOG SocketIOClient{/}: Removing handler for event: newMessage
    2020-12-03 14:24:42.570656+0530 Capshot[27105:8609238] LOG SocketIOClient{/}: Adding handler for event: newMessage
    2020-12-03 14:24:42.571250+0530 Capshot[27105:8609238] LOG SocketIOClient{/}: Removing handler for event: getDeck
    2020-12-03 14:24:42.572040+0530 Capshot[27105:8609238] LOG SocketIOClient{/}: Adding handler for event: getDeck
    2020-12-03 14:24:42.572203+0530 Capshot[27105:8609238] LOG SocketIOClient{/}: Removing handler for event: conversationsUpdate
    2020-12-03 14:24:42.572669+0530 Capshot[27105:8609238] LOG SocketIOClient{/}: Adding handler for event: conversationsUpdate
    2020-12-03 14:24:42.573538+0530 Capshot[27105:8609238] LOG SocketIOClient{/}: Removing handler for event: clearConversation
    2020-12-03 14:24:42.573761+0530 Capshot[27105:8609238] LOG SocketIOClient{/}: Adding handler for event: clearConversation
    2020-12-03 14:24:42.573916+0530 Capshot[27105:8609238] LOG SocketIOClient{/}: Removing handler for event: msgReq
    2020-12-03 14:24:42.574852+0530 Capshot[27105:8609238] LOG SocketIOClient{/}: Adding handler for event: msgReq
    2020-12-03 14:24:42.575015+0530 Capshot[27105:8609238] LOG SocketIOClient{/}: Removing handler for event: getMessages
    2020-12-03 14:24:42.575273+0530 Capshot[27105:8609238] LOG SocketIOClient{/}: Adding handler for event: getMessages
    2020-12-03 14:24:42.575456+0530 Capshot[27105:8609238] LOG SocketIOClient{/}: Removing handler for event: reaction
    2020-12-03 14:24:42.575640+0530 Capshot[27105:8609238] LOG SocketIOClient{/}: Adding handler for event: reaction
    2020-12-03 14:24:42.575801+0530 Capshot[27105:8609238] LOG SocketIOClient{/}: Adding handler for event: disconnect
    2020-12-03 14:24:42.575952+0530 Capshot[27105:8609238] LOG SocketIOClient{/}: Removing handler for event: err
    2020-12-03 14:24:42.576403+0530 Capshot[27105:8609238] LOG SocketIOClient{/}: Adding handler for event: err
    2020-12-03 14:24:42.609010+0530 Capshot[27105:8609466] LOG SocketEngine: Got message: 40
    2020-12-03 14:24:42.616593+0530 Capshot[27105:8609238] LOG SocketParser: Parsing 0
    2020-12-03 14:24:42.616835+0530 Capshot[27105:8609238] LOG SocketParser: Decoded packet as: SocketPacket {type: 0; data: []; id: -1; placeholders: 0; nsp: /}
    2020-12-03 14:24:42.616914+0530 Capshot[27105:8609238] LOG SocketIOClient{/}: Socket connected
    2020-12-03 14:24:42.617001+0530 Capshot[27105:8609238] LOG SocketIOClient{/}: Handling event: statusChange with data: [connected, 3]
    2020-12-03 14:24:42.617096+0530 Capshot[27105:8609238] LOG SocketIOClient{/}: Handling event: connect with data: ["/"]
    2020-12-03 14:24:42.617294+0530 Capshot[27105:8609238] LOG SocketIOClient{/}: Emitting: 2["loadConversations"], Ack: false
    2020-12-03 14:24:42.617443+0530 Capshot[27105:8609477] LOG SocketEngine: Writing ws: 2["loadConversations"] has data: false
    2020-12-03 14:24:42.617807+0530 Capshot[27105:8609477] LOG SocketEngineWebSocket: Sending ws: 2["loadConversations"] as type: 4
    2020-12-03 14:25:06.749401+0530 Capshot[27105:8609477] LOG SocketEngine: Writing ws:  has data: false
    2020-12-03 14:25:06.750079+0530 Capshot[27105:8609238] LOG SocketIOClient{/}: Handling event: ping with data: []
    2020-12-03 14:25:06.750090+0530 Capshot[27105:8609477] LOG SocketEngineWebSocket: Sending ws:  as type: 2
    2020-12-03 14:25:06.770664+0530 Capshot[27105:8609934] LOG SocketEngine: Got message: 3
    2020-12-03 14:25:06.771292+0530 Capshot[27105:8609238] LOG SocketIOClient{/}: Handling event: pong with data: []
    2020-12-03 14:25:31.872126+0530 Capshot[27105:8609502] LOG SocketEngine: Writing ws:  has data: false
    2020-12-03 14:25:31.872126+0530 Capshot[27105:8609238] LOG SocketIOClient{/}: Handling event: ping with data: []
    2020-12-03 14:25:31.872931+0530 Capshot[27105:8609502] LOG SocketEngineWebSocket: Sending ws:  as type: 2
    2020-12-03 14:25:31.892893+0530 Capshot[27105:8609934] LOG SocketEngine: Got message: 3
    2020-12-03 14:25:31.893541+0530 Capshot[27105:8609238] LOG SocketIOClient{/}: Handling event: pong with data: []
    

    I am doing anything wrong with Socket initialisations?

    opened by dev-aj-catalystmi 27
  • Unable to receive data send by the server on connect

    Unable to receive data send by the server on connect

    I am not sure if this is a server side issue or a client side issue but if I connect to my server with socket.io via JavaScript it works, so at a minimum the swift client is behaving different here:

    I have a flask-socket.io python server that, in its connect handler emits an 'update_device' event to the client so that the client gets the initial state of everything. The server then subsequently sends 'update_device' events when it encounters updates.

    My Swift client is able to receive the subsequent update messages but it fails to receive the initial one. In the logs I can see that this event reaches it but that happens before the connect finishes, which kinda makes sense given that this happens on the server side inside the connect handler.

    The JavaScript implementation doesn't seem to have a problem with that, but the Swift implementation does not seem to like this and simply drops that update.

    Here's the entire client side log.

    LOG SocketIOClient{/device}: Adding handler for event: connect
    LOG SocketIOClient{/device}: Adding handler for event: device_update
    LOG SocketIOClient{/device}: Handling event: statusChange with data: [connecting, 2]
    LOG SocketIOClient{/device}: Joining namespace /device
    LOG SocketManager: Tried connecting socket when engine isn't open. Connecting
    LOG SocketManager: Adding engine
    LOG SocketEngine: Starting engine. Server: http://localhost:8080
    LOG SocketEngine: Handshaking
    LOG SocketEnginePolling: Doing polling GET http://localhost:8080/socket.io/?transport=polling&b64=1&EIO=4
    LOG SocketEnginePolling: Got polling response
    LOG SocketEnginePolling: Got poll message: 0{"sid":"yLEza-oHKIW_iZziAAAC","upgrades":["websocket"],"pingTimeout":20000,"pingInterval":25000}
    LOG SocketEngine: Got message: 0{"sid":"yLEza-oHKIW_iZziAAAC","upgrades":["websocket"],"pingTimeout":20000,"pingInterval":25000}
    LOG SocketEnginePolling: Doing polling GET http://localhost:8080/socket.io/?transport=polling&b64=1&EIO=4&sid=yLEza-oHKIW_iZziAAAC
    LOG SocketManager: Engine opened Connect
    LOG SocketEngine: Writing poll: 0/device,{"udid":"1"} has data: false
    LOG SocketEnginePolling: Sending poll: 0/device,{"udid":"1"} as type: 4
    LOG SocketEnginePolling: Created POST string: 40/device,{"udid":"1"}
    LOG SocketEnginePolling: POSTing
    LOG SocketEnginePolling: Doing polling POST http://localhost:8080/socket.io/?transport=polling&b64=1&EIO=4&sid=yLEza-oHKIW_iZziAAAC
    LOG SocketEnginePolling: Got polling response
    LOG SocketEnginePolling: Got poll message: 42/device,["device_update",{"value":5,"message":"My message"}]\^^40/device,{"sid":"cFuzvmNfCD6TKA6EAAAD"}
    LOG SocketEngine: Got message: 42/device,["device_update",{"value":5,"message":"My message"}]
    LOG SocketEngine: Got message: 40/device,{"sid":"cFuzvmNfCD6TKA6EAAAD"}
    LOG SocketParser: Parsing 2/device,["device_update",{"value":5,"message":"My message"}]
    LOG SocketEnginePolling: Doing polling GET http://localhost:8080/socket.io/?transport=polling&b64=1&EIO=4&sid=yLEza-oHKIW_iZziAAAC
    LOG SocketParser: Decoded packet as: SocketPacket {type: 2; data: [device_update, {
        message = "My message";
        value = 5;
    }]; id: -1; placeholders: -1; nsp: /device}
    LOG SocketParser: Parsing 0/device,{"sid":"cFuzvmNfCD6TKA6EAAAD"}
    LOG SocketParser: Decoded packet as: SocketPacket {type: 0; data: [{
        sid = cFuzvmNfCD6TKA6EAAAD;
    }]; id: -1; placeholders: -1; nsp: /device}
    LOG SocketIOClient{/device}: Socket connected
    LOG SocketIOClient{/device}: Handling event: statusChange with data: [connected, 3]
    LOG SocketIOClient{/device}: Handling event: connect with data: ["/device", ["sid": cFuzvmNfCD6TKA6EAAAD]]
    >>> CONNECT HANDLER CALLED
    unable to parse data: ["/device", ["sid": cFuzvmNfCD6TKA6EAAAD]]
    
    opened by michaelochs 2
  • Fix SwiftUI Previews (support arm64 on simulators)

    Fix SwiftUI Previews (support arm64 on simulators)

    This library is breaking SwiftUI Previews, and it looks like I'm not the only one with the issue.

    Error: x.swift:10:8: Could not find module 'SocketIO' for target 'arm64-apple-ios-simulator'; found: x86_64-apple-ios-simulator, at: /Users/x/Library/Developer/Xcode/DerivedData/CricHQ-dmjqadgxdcinrrcgwugqdedztquy/Build/Products/Debug-iphonesimulator/SocketIO.swiftmodule

    opened by dan-ryan 7
  • Could not connect to server

    Could not connect to server

    @nuclearace when I try to chat with another id , first time its was emit and listen normally after that its was shown below and also in android it was worked fine ..

    NSLocalizedDescription=Could not connect to the server., NSErrorFailingURLStringKey=https://demo1.something.com:8011/socket.io/?transport=polling&b64=1, NSErrorFailingURLKey=https://demo1. something.com:8011/socket.io/?transport=polling&b64=1, _kCFStreamErrorDomainKey=1}

    opened by Vigneshkumarzx 1
  • Doing Polling issue from swift client when using v4.5.2 socket.IO in a node.js server

    Doing Polling issue from swift client when using v4.5.2 socket.IO in a node.js server

    Hi, to make a connection to v4.5.2 socket.IO in a node.js server, I updated swift client from version 15.2.0 to version 16.0.1 The new v4.5.2 socket.IO works perfectly well with the java and Android client, but there are two issues on swift client that I'm dealing with them now:

    1- The transport is always set to polling. In order to fix it, I set.forceWebsockets(true), but it is not possible to make an establish a connection after it. It's our first priority to fix this issue. The transport should be set to webcocket Here is the logs

    2022-09-16 18:05:40.275708+0200 app-name[1597:395115] LOG OnAckCallback: OnAckCallback for 0 being released
    2022-09-16 18:05:54.825999+0200 app-name[1597:395444] LOG SocketEnginePolling: Got polling response
    2022-09-16 18:05:54.826233+0200 app-name[1597:395444] LOG SocketEnginePolling: Got poll message: 2
    2022-09-16 18:05:54.826520+0200 app-name[1597:395444] LOG SocketEngine: Got message: 2
    2022-09-16 18:05:54.826844+0200 app-name[1597:395115] LOG SocketIOClient: Handling event: ping with data: []
    2022-09-16 18:05:54.827029+0200 app-name[1597:395444] LOG SocketEnginePolling: Doing polling GET https://<our-socket-url>/socket.io/?transport=polling&b64=1&EIO=4&sid=MmDRjwTzgXduf3x0AAAE
    2022-09-16 18:05:54.827843+0200 app-name[1597:395444] LOG SocketEngine: Writing poll:  has data: false
    2022-09-16 18:05:54.828001+0200 app-name[1597:395444] LOG SocketEnginePolling: Sending poll:  as type: 3
    2022-09-16 18:05:54.828180+0200 app-name[1597:395444] LOG SocketEnginePolling: Created POST string: 3
    2022-09-16 18:05:54.828575+0200 app-name[1597:395444] LOG SocketEnginePolling: POSTing
    2022-09-16 18:05:54.828736+0200 app-name[1597:395444] LOG SocketEnginePolling: Doing polling POST https://<our-socket-url>/socket.io/?transport=polling&b64=1&EIO=4&sid=MmDRjwTzgXduf3x0AAAE
    

    2- The second issue is, if more than one iOS devices makes a connection, all devices will be disconnected.

    Here the swift code:

      public init() {
          let url = URL(string: DefaultURL.base)
          manager = SocketManager(socketURL: url!, config: [.log(true),
                                                            .reconnects(true),
                                                            .reconnectAttempts(3)])
          
          socket = manager.socket(forNamespace: DefaultURL.namespace)
          
          socketConnectEvent()
          socketDisconnectEvent()
          connect()
      }
      
      
      
      private func socketConnectEvent() {
            
            socket.on(clientEvent: .connect) { [weak self]  data, ack in
                guard let this = self else { return }
                this.isConnected = true
                this.observer.onConnect()
    
            }
      }
      
      
      private func socketDisconnectEvent() {
             socket.on(clientEvent: .disconnect) { [weak self] data, ack in
                 guard let this = self else { return }
                
                 this.isConnected = false
                 this.observer.onDisconnect()
                
                 this.loginCallback?(false, "Socket disconnect")
                 this.loginCallback = nil
           }
      }
    
    
      public func connect() {
            Logger.logInfo("Connecting socket…")
            socket.connect(timeoutAfter: 1, withHandler: { [weak self] in
                guard let this = self else { return }
                Logger.logError("Failed to connect")
                
                this.eventHandler?(.connectionDidFailed)
           })
       }
    
    

    Your help will be appreciated

    opened by rouzbeh-abadi 2
  • ERROR: Property 'defaultSocket' not found on object of type 'SocketManager *'

    ERROR: Property 'defaultSocket' not found on object of type 'SocketManager *'

    manager = [[SocketManager alloc] initWithSocketURL...]; socket = self.manager.defaultSocket; // ERROR: Property 'defaultSocket' not found on object of type 'SocketManager *' [self.socket connect]; // ERROR: No visible @interface for 'SocketIOClient' declares the selector 'connect'

    opened by Wuou 0
  • Build for distribution

    Build for distribution

    Hello,

    I would like to use SocketIO as a dynamic dependency of my xcframework

    I have checked your project and see that you don't use option BUILD_LIBRARY_FOR_DISTRIBUTION:

    189948772-d0117bcd-d267-46ac-aa2f-6f2ad0fdc5fb

    why?

    This option

    Ensures that your libraries are built for distribution. For Swift, this enables support for library evolution and generation of a module interface file

    https://xcodebuildsettings.com

    Without forcing this option in Pods project there's the following error in runtime:

    dyld[20229]: Symbol not found: _$s8SocketIO0A11ClientEventO5erroryA2CmFWC
      Referenced from: .../Frameworks/MyFramework.framework/MyFramework
      Expected in: .../MyApp.app/Frameworks/SocketIO.framework/SocketIO
    

    I can confirm this error running project with the dependencies under Rosetta with some of these options used:

    config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = ’x.0'
    config.build_settings.delete 'IPHONEOS_DEPLOYMENT_TARGET'
    

    P.S. Also these issues have relation to the ticket #1356 #1269

    Current workaround is to add at the end of project's Podfile where Socket-IO integrated:

    # Socket.IO-Client-Swift
    post_install do |lib|
        lib.pods_project.targets.each do |target|
          if target.name == 'Socket.IO-Client-Swift'
              target.build_configurations.each do |config|
                  config.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'YES'
              end
          end
        end
    end
    

    and remove if used:

    config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = ’x.0'
    config.build_settings.delete 'IPHONEOS_DEPLOYMENT_TARGET'
    
    opened by GRyabkin 0
Releases(v16.0.1)
Owner
Socket.IO
Socket.IO
Socket framework for Swift using the Swift Package Manager. Works on iOS, macOS, and Linux.

BlueSocket Socket framework for Swift using the Swift Package Manager. Works on iOS, macOS, and Linux. Prerequisites Swift Swift Open Source swift-4.0

Kitura 1.3k Jan 3, 2023
DispatchSource based socket framework written in pure Swift

SwiftDSSocket Overview SwiftDSSocket is a purely swift based asynchronous socket framework built atop DispatchSource. Function signatures are pretty m

Yi Huang 65 Nov 15, 2022
SwiftWebSocket - Conforming WebSocket (RFC 6455) client library for iOS and Mac OSX.

SwiftWebSocket Conforming WebSocket (RFC 6455) client library for iOS and Mac OSX. SwiftWebSocket passes all 521 of the Autobahn's fuzzing tests, incl

Josh Baker 1.5k Jan 5, 2023
Websockets in swift for iOS and OSX

Starscream is a conforming WebSocket (RFC 6455) library in Swift. Features Conforms to all of the base Autobahn test suite. Nonblocking. Everything ha

Dalton 7.5k Jan 4, 2023
Socket.io iOS and OSX Client compatible with v1.0 and later

SocketIO-Kit ⚠️ This project is no longer maintained. Please use the official framework Socket.IO-Client-Swift. SocketIO-Kit is a Socket.io iOS client

Ricardo Pereira 140 Mar 9, 2022
Socket.IO-client for iOS/OS X.

Socket.IO-Client-Swift Socket.IO-client for iOS/OS X.

Socket.IO 4.9k Jan 1, 2023
🔌 Non-blocking TCP socket layer, with event-driven server and client.

Original authors Honza Dvorsky - http://honzadvorsky.com, @czechboy0 Matthias Kreileder - @matthiaskr1 At the request of the original authors, we ask

Vapor Community 574 Dec 7, 2022
🔌 Non-blocking TCP socket layer, with event-driven server and client.

Original authors Honza Dvorsky - http://honzadvorsky.com, @czechboy0 Matthias Kreileder - @matthiaskr1 At the request of the original authors, we ask

Vapor Community 574 Dec 7, 2022
🔌 Non-blocking TCP socket layer, with event-driven server and client.

Original authors Honza Dvorsky - http://honzadvorsky.com, @czechboy0 Matthias Kreileder - @matthiaskr1 At the request of the original authors, we ask

Vapor Community 574 Dec 7, 2022
Socket framework for Swift using the Swift Package Manager. Works on iOS, macOS, and Linux.

BlueSocket Socket framework for Swift using the Swift Package Manager. Works on iOS, macOS, and Linux. Prerequisites Swift Swift Open Source swift-4.0

Kitura 1.3k Jan 3, 2023
Socket framework for Swift using the Swift Package Manager. Works on iOS, macOS, and Linux.

BlueSocket Socket framework for Swift using the Swift Package Manager. Works on iOS, macOS, and Linux. Prerequisites Swift Swift Open Source swift-5.1

Kitura 1.3k Dec 26, 2022
Asynchronous socket networking library for Mac and iOS

CocoaAsyncSocket CocoaAsyncSocket provides easy-to-use and powerful asynchronous socket libraries for macOS, iOS, and tvOS. The classes are described

Robbie Hanson 12.3k Jan 8, 2023
JustLog brings logging on iOS to the next level. It supports console, file and remote Logstash logging via TCP socket with no effort. Support for logz.io available.

JustLog JustLog takes logging on iOS to the next level. It supports console, file and remote Logstash logging via TCP socket with no effort. Support f

Just Eat 509 Dec 10, 2022
An iOS App which shows live AQI (Air quality index) data for different cities using Web-socket

AQI - Assignment This is an iOS App which shows live AQI (Air quality index) dat

Pratik Prajapati 3 Jul 21, 2022
DispatchSource based socket framework written in pure Swift

SwiftDSSocket Overview SwiftDSSocket is a purely swift based asynchronous socket framework built atop DispatchSource. Function signatures are pretty m

Yi Huang 65 Nov 15, 2022
DispatchSource based socket framework written in pure Swift

SwiftDSSocket Overview SwiftDSSocket is a purely swift based asynchronous socket framework built atop DispatchSource. Function signatures are pretty m

Yi Huang 65 Nov 15, 2022
A collection of socket utilities in pure Swift

SwifterSockets A collection of socket utilities in pure Swift SwifterSockets is part of the Swiftfire webserver project. The Swiftfire website The ref

Rien 58 Sep 9, 2022
MVVM project to show AQI of cities via web socket

Air Quality Monitoring Application Swift project with JSON parsing using codable About the application The app consists of live realtime data from the

Pran Kishore 0 Nov 27, 2021
This app is using web-socket for realtime updation of aqi for dedicated inidan cities.

CityWiseAQI This app is using web-socket for realtime updation of aqi for dedicated inidan cities. We're following MVVM architecture in this app. This

Vipul Kumar 2 Feb 7, 2022
Swift async/await based socket

Socket Swift async/await based socket library Introduction This library exposes an idiomatic Swift API for interacting with POSIX sockets via an async

null 89 Dec 29, 2022