Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Domain=NSPOSIXErrorDomain Code=61

I'm trying to connect between the client(iOS app) and the server(Node.js) with using SocketRocket and ws like this below.

iOS(SocketRocket):

NSURL *url = [NSURL urlWithString:@"ws://localhost:8080"];
SRWebSocket *_socket = [SRWebSocket alloc] initWithURLRequest:[NSURLRequest requestWithURL:url];
_socket.delegate = self;
[_socket open];

/* SRWebSocketDelegate */
-(void)webSocketDidOpen:(SRWebSocket*)webSocket{
    [webSocket send:@"something"];
}
-(void)webSocket:(SRWebSocket*)webSocket didReceiveMessage:(id)message{
    NSLog(@"didReceiveMessage: %@",[message description]);
}
-(void)webSocket:(SRWebSocket*)webSocket didFailWithError:(NSError*)error{
    NSLog(@"the Error: %@",error);
}

Node.js(ws):

var WebSocketServer = require('ws').Server
var wss = new WebSocketServer({
    host:'localhost',
    port:8080
});
wss.on('connection',function(ws){
    ws.on('message',function(message){
        console.log('received: %s', message);
        ws.send(message);
    });
});

Then, I got the message this below:

the error: Error Domain=NSPOSIXErrorDomain Code=61 "The operation couldn’t be completed. Connection refused"

I've searched to solve this, but I couldn't find the exactly solution for this. How do I solve this??

like image 627
user3278637 Avatar asked Feb 06 '14 09:02

user3278637


2 Answers

Connecting to the wi-fi network on your iPhone. Maybe solved that problem.

like image 112
serdaryillar Avatar answered Oct 05 '22 12:10

serdaryillar


Change localhost to your actual ip address like 10.28.8.146 can solve your problem.

like image 20
potato Avatar answered Oct 05 '22 13:10

potato