nuclearace / Socket.IO-Client-Swift

socket.io-client for Swift
Other
361 stars 53 forks source link

Remote server connection error? #53

Closed Dmurph24 closed 9 years ago

Dmurph24 commented 9 years ago

I am trying to connect a socket to my remote server with the following syntax: let socket = SocketIOClient(socketURL: "my.server.com:port") I have tried this with and without the port referenced and http:// added

When I call socket.connect() I receive the following errors:

SocketClient: Adding handler for event: connect SocketClient: Adding handler for event: error SocketClient: Adding engine SocketEngine: Starting engine SocketEngine: Handshaking SocketEngine: Doing polling request ERROR SocketClient: Error: Could not connect to the server. SocketClient: Handling event: error with data: Optional([Could not connect to the server.])

I am 100% certain that the server is handling appropriately. I did notice all the examples given using this library are using localhost instead of a remote server connection. Something else to note is that the server is hosted by heroku. However, we have an equivalent app that is for android which connects to it just fine.

Is anyone able to explain why I am having this issue?

nuclearace commented 9 years ago

What version of socket.io is the server running?

Dmurph24 commented 9 years ago

The server is running on version 1.3.5 for socket.io, the newest version

nuclearace commented 9 years ago

Would you be able to provide your server url? Because I'm able to connect to my test server fine.

nuclearace commented 9 years ago

The only thing I've noticed is if you pass http:// or leave out the https:// when the port is actually tls.

nuclearace commented 9 years ago

Oh, you might need to actually specify the socket.io url.

nuclearace commented 9 years ago

Including the port.

nuclearace commented 9 years ago

Wait, nvm. I think I can connect.

nuclearace commented 9 years ago

Dmurph24 commented 9 years ago

So the problem was I needed the extra parameters? Can you explain? I will try this out when I have my laptop handy.

nuclearace commented 9 years ago

You shouldn't need them, since those are the default, they're just there for testing.

nuclearace commented 9 years ago

I'm not sure why it's saying Could not connect to the server. I think that's something coming from the Engine here https://github.com/nuclearace/Socket.IO-Client-Swift/blob/master/SocketIOClientSwift/SocketEngine.swift#L360

Dmurph24 commented 9 years ago

But the connection is working for you? Can you provide your code?

Dmurph24 commented 9 years ago

I used your parameters and it now is connecting!

nuclearace commented 9 years ago

I can provide a base case.

import Foundation

let socket = SocketIOClient(socketURL: "spotbox.herokuapp.com", options: ["log": true])

socket.on("connect") {data, ack in
    println("socket connected")
}

socket.connect()

CFRunLoopRun()
nuclearace commented 9 years ago

This assumes you submodule the client, and it's OS X

Dmurph24 commented 9 years ago

I really have no idea why its working now, because I had exactly this before but its possible I changed one little thing. Most importantly, its working now! Thanks so much for the help!

nuclearace commented 9 years ago

No problem.

codalamanp commented 7 years ago

How to know if timeout error occurs while connecting the server in this example?

RajeshwarSharma commented 7 years ago

I didn't get the correct answer for this.