[英]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. 我正在尝试使用SocketRocket和下面的ws在客户端(iOS应用)和服务器(Node.js)之间进行连接。
iOS(SocketRocket): 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): 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??
我该如何解决?
Connecting to the wi-fi network on your iPhone. 连接到iPhone上的wi-fi网络。 Maybe solved that problem.
也许解决了这个问题。
将localhost
更改为您的实际IP地址(如10.28.8.146
可以解决您的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.