Domain = NSPOSIXErrorDomain Code = 61

I am trying to connect between a client (iOS application) and a server (Node.js) using SocketRocket and ws, as shown 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 below:

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

I was looking to solve this problem, but I could not find the exact solution for this. How to solve this?

+4
source share
2 answers

Connect to a Wi-Fi network on your iPhone. Perhaps this problem has been resolved.

+1
source

Change localhostto your actual IP address, for example 10.28.8.146, to solve your problem.

0
source

Source: https://habr.com/ru/post/1525584/


All Articles