An example of socket.io-client for Swift in the form of a TicTacToe app
![](http://i.imgur.com/wOkugkml.jpg)nuclearace / socket.io-client-swift-example Goto Github PK
View Code? Open in Web Editor NEWAn example of socket.io-client for Swift
An example of socket.io-client for Swift
An example of socket.io-client for Swift in the form of a TicTacToe app
![](http://i.imgur.com/wOkugkml.jpg)Can you provide an example of handling timeout
on emitWithAck().timingOut()
?
Thanks
What I need for run this example? I have Xcode 6.2(6C131e), I download the project, I opened it with Xcode and I'm having 83 errors
Can you make a step by step procedure to run it for beginners please. Thank you!
Hello,
I would like to use SocketIO as an dynamic dependency of my xcframework
I have checked your project and see that you don't use option BUILD_LIBRARY_FOR_DISTRIBUTION:
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:
dyld[20229]: Symbol not found: _$s8SocketIO0A11ClientEventO5erroryA2CmFWC
Referenced from: .../Frameworks/MyFramework.framework/MyFramework
Expected in: .../MyApp.app/Frameworks/SocketIO.framework/SocketIO
I went through the sample and I can't see the disconnect method for disconnecting the socket.
I have called the socket.disconnect
in deinit
method of my iOS app. Is this the right way of doing it?
Thanks a lot for this library.
I don't know too well the source codes of all dependencies - and I'm afraid to hard-set their Swift versions to 4.2 --- how should I go about this?
I tried to run the sample using simulator and localhost server but app unable to connect, see the screenshot below:
I am not sure is it a problem of iOS simulator restrictions or maybe Info.plist can be tweaked somehow to allow connections to localhost (something with ATS - apple transport security)?
I wanted to check that your sample works OK and then start modifying it as a base template to my needs but I can't pass the first milestone and verify that socket.io works with iOS. I am pretty sure it does but I couldn't verify it for myself with your sample.
What I tried so far:
pod 'Socket.IO-Client-Swift', '~> 15.2.0'
P.S. I want to assure you that I followed your FAQ and didn't modify code of your sample (only for trying (1) and changing server address), so manager instance is global
I download the demo app, run well in simulator. But get error when using iPad, I use
socket.onAny {
print("Got event: ($0.event), with items: ($0.items!)")
}
to print log:
Got event: error, with items: ["Could not connect to the server."]
is anyone met this issue?
I need all the emitted Keys and how to listen all the events for iOS or which backend tech is used?
Building on iOS 14.1 and Xcode 12.2.
The server runs as expected. But the iOS app has trouble connecting to the server. Fails with an error: ["Error"]
.
I have verified the server by connecting a js client. Which was able to send and receive data.
Logs:
2020-11-30 02:26:11.033013+0530 TicTacIOiOS[23659:579640] ERROR SocketEngine: Error
2020-11-30 02:26:11.033410+0530 TicTacIOiOS[23659:579546] ERROR SocketManager: Error
2020-11-30 02:26:11.033451+0530 TicTacIOiOS[23659:579640] LOG SocketEngine: Engine is being closed.
2020-11-30 02:26:11.033890+0530 TicTacIOiOS[23659:579546] LOG SocketIOClient{/}: Handling event: error with data: ["Error"]
Got event: error, with items: ["Error"]
2020-11-30 02:26:11.035820+0530 TicTacIOiOS[23659:579640] LOG SocketEnginePolling: Created POST string: 1:1
2020-11-30 02:26:11.038152+0530 TicTacIOiOS[23659:579640] LOG SocketEnginePolling: Doing polling POST http://localhost:8900/socket.io/?transport=polling&b64=1&sid=cVuuxVgF13AZlC72AABx
2020-11-30 02:26:11.040059+0530 TicTacIOiOS[23659:579546] LOG SocketManager: Starting reconnect
2020-11-30 02:26:11.040529+0530 TicTacIOiOS[23659:579546] LOG SocketIOClient{/}: Handling event: statusChange with data: [connecting, 2]
Got event: statusChange, with items: [connecting, 2]
2020-11-30 02:26:11.041098+0530 TicTacIOiOS[23659:579546] LOG SocketIOClient{/}: Handling event: reconnect with data: ["Error"]
Got event: reconnect, with items: ["Error"]
2020-11-30 02:26:11.041764+0530 TicTacIOiOS[23659:579546] LOG SocketManager: Trying to reconnect
2020-11-30 02:26:11.042350+0530 TicTacIOiOS[23659:579546] LOG SocketIOClient{/}: Handling event: reconnectAttempt with data: [-1]
Got event: reconnectAttempt, with items: [-1]
2020-11-30 02:26:11.042833+0530 TicTacIOiOS[23659:579546] LOG SocketManager: Scheduling reconnect in 16.22947678523183s
2020-11-30 02:26:11.042896+0530 TicTacIOiOS[23659:579640] LOG SocketEngine: Starting engine. Server: http://localhost:8900
2020-11-30 02:26:11.043875+0530 TicTacIOiOS[23659:579640] LOG SocketEngine: Handshaking
2020-11-30 02:26:11.044719+0530 TicTacIOiOS[23659:579640] LOG SocketEnginePolling: Doing polling GET http://localhost:8900/socket.io/?transport=polling&b64=1
2020-11-30 02:26:11.074289+0530 TicTacIOiOS[23659:579682] LOG SocketEnginePolling: Got polling response
2020-11-30 02:26:11.074494+0530 TicTacIOiOS[23659:579682] LOG SocketEnginePolling: Got poll message: 0{"sid":"BamXcopA70j7dQNAAABy","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":5000}
2020-11-30 02:26:11.074696+0530 TicTacIOiOS[23659:579682] LOG SocketEngine: Got message: 0{"sid":"BamXcopA70j7dQNAAABy","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":5000}
2020-11-30 02:26:11.077580+0530 TicTacIOiOS[23659:579546] LOG SocketIOClient{/}: Handling event: ping with data: []
2020-11-30 02:26:11.077657+0530 TicTacIOiOS[23659:579682] LOG SocketEnginePolling: Doing polling GET http://localhost:8900/socket.io/?transport=polling&b64=1&sid=BamXcopA70j7dQNAAABy
Got event: ping, with items: []
2020-11-30 02:26:11.078145+0530 TicTacIOiOS[23659:579546] LOG SocketManager: Engine opened Connect
2020-11-30 02:26:11.078371+0530 TicTacIOiOS[23659:579546] LOG SocketIOClient{/}: Socket connected
2020-11-30 02:26:11.078734+0530 TicTacIOiOS[23659:579546] LOG SocketIOClient{/}: Handling event: statusChange with data: [connected, 3]
Got event: statusChange, with items: [connected, 3]
2020-11-30 02:26:11.079113+0530 TicTacIOiOS[23659:579546] LOG SocketIOClient{/}: Handling event: connect with data: ["/"]
Got event: connect, with items: ["/"]
2020-11-30 02:26:11.080950+0530 TicTacIOiOS[23659:579682] LOG SocketEngine: Writing poll: has data: false
2020-11-30 02:26:11.081774+0530 TicTacIOiOS[23659:579682] LOG SocketEnginePolling: Sending poll: as type: 2
2020-11-30 02:26:11.082202+0530 TicTacIOiOS[23659:579682] LOG SocketEnginePolling: Created POST string: 1:2
2020-11-30 02:26:11.082650+0530 TicTacIOiOS[23659:579682] LOG SocketEnginePolling: POSTing
2020-11-30 02:26:11.083371+0530 TicTacIOiOS[23659:579682] LOG SocketEnginePolling: Doing polling POST http://localhost:8900/socket.io/?transport=polling&b64=1&sid=BamXcopA70j7dQNAAABy
2020-11-30 02:26:11.103587+0530 TicTacIOiOS[23659:579546] LOG SocketIOClient{/}: Handling event: websocketUpgrade with data: [["connection": "Upgrade", "sec-websocket-accept": "XnZbiSNCaCpMqSvXi3gbGPX4+Go=", "upgrade": "websocket"]]
Got event: websocketUpgrade, with items: [["connection": "Upgrade", "sec-websocket-accept": "XnZbiSNCaCpMqSvXi3gbGPX4+Go=", "upgrade": "websocket"]]
2020-11-30 02:26:11.104030+0530 TicTacIOiOS[23659:579634] LOG SocketEngineWebSocket: Sending ws: probe as type: 2
2020-11-30 02:26:11.106585+0530 TicTacIOiOS[23659:579635] LOG SocketEngine: Got message: 3probe
2020-11-30 02:26:11.109712+0530 TicTacIOiOS[23659:579635] LOG SocketEngine: Received probe response, should upgrade to WebSockets
2020-11-30 02:26:11.112925+0530 TicTacIOiOS[23659:579635] LOG SocketEngine: Upgrading transport to WebSockets
2020-11-30 02:26:11.118305+0530 TicTacIOiOS[23659:579635] LOG SocketEnginePolling: Sending poll: as type: 6
2020-11-30 02:26:11.133363+0530 TicTacIOiOS[23659:579546] LOG SocketIOClient{/}: Handling event: pong with data: []
Got event: pong, with items: []
2020-11-30 02:26:11.134611+0530 TicTacIOiOS[23659:579635] LOG SocketEngine: Flushing probe wait
2020-11-30 02:26:11.138767+0530 TicTacIOiOS[23659:579635] LOG SocketEnginePolling: Got polling response
2020-11-30 02:26:11.139378+0530 TicTacIOiOS[23659:579635] LOG SocketEngine: Switching to WebSockets
2020-11-30 02:26:11.139910+0530 TicTacIOiOS[23659:579635] LOG SocketEngineWebSocket: Sending ws: as type: 5
2020-11-30 02:26:11.141147+0530 TicTacIOiOS[23659:579635] LOG SocketEngine: Flushing probe wait
Steps to reproduce:
pod install
cd server && npm install && node index.js
Hi,
I successfully setup all configuration steps and also its connected to my local machine but when I tap on any button its crashed due to the above reason. Also, I checked its properly connected the action but still its crashed. Can you please help me to resolve this issue?
Log:
Attempting to connect to http://192.168.5.60:8900
Optional(<SocketIO.SocketIOClient: 0x15e62520>)
Thanks
Nikunj
Hello,
I'm trying to get socket.io-client-swift-example running. I'm on step "Setup First Client." I've opened the project in Xcode but when I try to build and run I'm hit with a host of errors, all related to missing files:
<unknown>:0: error: no such file or directory: '/Users/pzurek/dev/ios/sockets/socket.io-client-swift-example/TicTacIOiOS/SocketIOClientSwift/Source/SocketIOClient.swift'
<unknown>:0: error: no such file or directory: '/Users/pzurek/dev/ios/sockets/socket.io-client-swift-example/TicTacIOiOS/SocketIOClientSwift/Source/WebSocket.swift'
<unknown>:0: error: no such file or directory: '/Users/pzurek/dev/ios/sockets/socket.io-client-swift-example/TicTacIOiOS/SocketIOClientSwift/Source/SocketEngineWebsocket.swift'
<unknown>:0: error: no such file or directory: '/Users/pzurek/dev/ios/sockets/socket.io-client-swift-example/TicTacIOiOS/SocketIOClientSwift/Source/SocketTypes.swift'
**<snip>**
<unknown>:0: error: no such file or directory: '/Users/pzurek/dev/ios/sockets/socket.io-client-swift-example/TicTacIOiOS/SocketIOClientSwift/Source/SocketEnginePacketType.swift'
<unknown>:0: error: no such file or directory: '/Users/pzurek/dev/ios/sockets/socket.io-client-swift-example/TicTacIOiOS/SocketIOClientSwift/Source/SocketStringReader.swift'
<unknown>:0: error: no such file or directory: '/Users/pzurek/dev/ios/sockets/socket.io-client-swift-example/TicTacIOiOS/SocketIOClientSwift/Source/SocketIOClientOption.swift'
Command /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc failed with exit code 1
I browsed the socket.io-client-swift-example repo and noticed that the SocketIOClientSwift directory references a non-existent project (clicking it leads to a 404 error on github):
So the next thing I did was go to the socket.io-client-swift repo and clone that to my socket.io-client-swift-example/TicTacIOiOS directory. Then I renamed it from socket.io-client-swift to SocketIOClientSwift since that is where Xcode was originally claiming it couldn't find the files.
Next I tried to build socket.io-client-swift-example again and indeed, most of the files are now found (the majority of error messages related to files not being found have disappeared). However, I am still getting errors about three missing files:
<unknown>:0: error: no such file or directory: '/Users/pzurek/dev/ios/sockets/socket.io-client-swift-example/TicTacIOiOS/SocketIOClientSwift/Source/SocketClientSpec.swift'
<unknown>:0: error: no such file or directory: '/Users/pzurek/dev/ios/sockets/socket.io-client-swift-example/TicTacIOiOS/SocketIOClientSwift/Source/SocketFixUTF8.swift'
<unknown>:0: error: no such file or directory: '/Users/pzurek/dev/ios/sockets/socket.io-client-swift-example/TicTacIOiOS/SocketIOClientSwift/Source/SwiftRegex.swift'
Command /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc failed with exit code 1
I've tried searching both repos for those files but I cannot find them. Any advice on how to proceed?
Thanks.
In javascript, we can do it like this:
const socket = io('http://localhost?token=abc');
but it doesn't work on your framework.
I love that you made an example of how to use Swift/Socket. I am new to both and still wrapping my head around how they work. I have a simple node server up and running, but not sure I understand how this all works.
I see you provided the node setup, but I don't really know what to do after 'node index.js'.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.