我使用openfire作为xmpp服务器,并希望通过Turnsocket传输文件。
openfire(本地)配置:
xmpp.auth.anonymous true
xmpp.domain local
xmpp.enabled true
xmpp.externalip proxy.local, 192.168.1.101, 127.0.0.1
xmpp.proxy.enabled true
xmpp.proxy.port 7777
xmpp.proxy.transfer.required false
xmpp.server.socket.active true
xmpp.session.conflict.limit 0
xmpp.socket.ssl.active true
我在本地环境中测试了文件传输,一个用户由Simulator(发件人)登录,另一个用户由设备(iPod,接收器)登录。
TURNSocket.m(均已更改),更改代理
+ (void)initialize {
...
proxyCandidates = [[NSMutableArray alloc] initWithObjects:@"local", nil];
...
}
在发件人和收件人上配置
- (BOOL)xmppStream:(XMPPStream *)sender didReceiveIQ:(XMPPIQ *)iq {
...
if ([TURNSocket isNewStartTURNRequest:iq]) {
NSLog(@"IS NEW TURN request Receive.. TURNSocket..................");
TURNSocket *turnSocket = [[TURNSocket alloc] initWithStream:xmppStream incomingTURNRequest:iq];
[turnSockets addObject:turnSocket];
[turnSocket startWithDelegate:self delegateQueue:dispatch_get_main_queue()];
[turnSocket release];
}
return YES;
}
设置并调用TURNSocket(发件人)
TURNSocket *turnSocket = [[TURNSocket alloc] initWithStream:[self xmppStream] toJID:user.primaryResource.jid];
[turnSockets addObject:turnSocket];
[turnSocket startWithDelegate:self delegateQueue:dispatch_get_main_queue()];
[turnSocket release];
didSucceed呼叫两者(发送者和接收者)
- (void)turnSocket:(TURNSocket *)sender didSucceed:(GCDAsyncSocket *)socket {
}
发送文件?发件人
- (void)turnSocket:(TURNSocket *)sender didSucceed:(GCDAsyncSocket *)socket {
NSData *dataF = [[NSData alloc] initWithContentsOfFile:
[[NSBundle mainBundle] pathForResource:@"a1" ofType:@"png"]];
[socket writeData:dataF withTimeout:60.0f tag:0];
}
OR:这里收到的数据? (接收器)
- (void)turnSocket:(TURNSocket *)sender didSucceed:(GCDAsyncSocket *)socket {
NSData *dataF = [[NSData alloc] init];
[socket readDataToData:dataF withTimeout:30.0 tag:0];
NSLog(@"dataF: %d", [dataF length]); // dataF: 0
}
有谁知道这是什么问题?
非常感谢!
答案 0 :(得分:-1)
要设置外部IP地址,您需要使用xmpp.proxy.externalip而不是xmpp.externalip