Search code examples
javascriptnode.jssocketsswift2xcode7.1

Socket IO not getting connected to server using swift


I've downloaded a sample socket project from github https://github.com/appcoda/SocketIOChat

I'm using EICapitan and I've installed node js and I've also setup the IP in the sample var socket: SocketIOClient = SocketIOClient(socketURL: NSURL(string: "http://192.168.1.2:3000")!) When I run node index.js command on terminal it shows Listening on *:3000 But when I run the sample app enter a name to connect user I dont receive any message like user connected. Is there something that I'm missing, I'm a beginner to node.js and socket.io. Any help is appreciated.


Solution

  • Seems like you are trying connect to incorrect ip address. Get your inet ip from ifconfig and place it to SocketIOClient. I would recommend you to use localhost or 127.0.0.1 for development instead of inet address