Closed elcocui closed 9 years ago
In your code it appears that you are calling connect before you actually add the handlers. It's more correct to add your handlers before you call connect. Because once you call connect there's no guarantee that your handler will be added in time to respond to the events.
Also, there really isn't any reason to call sendPing yourself, the socket will set up a timer to call it.
thank you. I will try the suggestions and let you know how it works
Any luck?
Did not try it yet sir. I have been out for a conference. Will let you know how it goes asap. Thanks for asking.
I tried the suggestions, but unfortunately, the event handlers are not being initiated. I'm suspecting that I made a mistake while setting up the Xcode project, but I have no idea what it is because there seem to be no errors or warnings. It would be really helpful if you could add an example app/project using swift.io sockets. Sorry for the trouble. You have done an incredible job with the code.
https://github.com/nuclearace/CytubeChatiOS/tree/1.1/CytubeChat1.0 Is what I made the client for.
Specifically check out: https://github.com/nuclearace/CytubeChatiOS/blob/1.1/CytubeChat1.0/CytubeRoom.swift https://github.com/nuclearace/CytubeChatiOS/blob/1.1/CytubeChat1.0/CytubeRoom.swift#L47 https://github.com/nuclearace/CytubeChatiOS/blob/1.1/CytubeChat1.0/CytubeRoom.swift#L297 https://github.com/nuclearace/CytubeChatiOS/blob/1.1/CytubeChat1.0/CytubeRoom.swift#L308
open() just calls connect()
thanks for the quick reply. Checking the code right now.
Also just as a sanity check, you are trying to connect to a socket.io server and not just a WebSockets server correct? This is only for socket.io. However if you're just trying to connect to a WebSockets server you'd probably be best using SocketRocket. You could use SocketIOClient.swift as an example of a delegate class.
You'd need to change
https://github.com/nuclearace/Socket.IO-Client-Swift/blob/master/SwiftIO/SocketIOClient.swift#L100 to
wss://\(self.socketURL)
or ws://\(self.socketURL)
. And then write your own parser for webSocket(webSocket:SRWebSocket!, didReceiveMessage message:AnyObject?)
, and handle the other delegate methods accordingly.
elcocui - Put a break point in SRWebSocket here:
https://github.com/square/SocketRocket/blob/master/SocketRocket/SRWebSocket.m#L476
Check the value for the delegate of SRWebSocket. Is it nil? It sounds to me as if your Socket-IO-Client object is probably disappearing. You might consider implementing a deinit() in whatever class you instantiate your Socket-IO-Client in (or in Socket-IO-Client itself) to see when / where your SRWebSocket delegate is going away. I'm guessing that you will discover that it's not persisting!
Hi, Im trying to make an IOS app to connect to arduino via a wifly shield. I got the shield listening in 192.168.1.111:8000. Im able to connect and disconnect to the wifly board, but I'm not able to send data. On further study, i found that the code is not firing func websocketdidopen() on opening the port (same with closing).The events including socket.on("connect") do not respond after connection is created. Please help me out. code:
import UIKit import Foundation class ViewController: UIViewController { var connectionStatus: Bool = false let socket = SocketIOClient(socketURL: "192.168.1.111:8000", opts: nil)
}