问题描述
我使用openfire作为xmpp服务器,并希望通过Turnsocket传输文件。
I used the openfire as the xmpp server, and want to transfer file via the Turnsocket.
openfire(本地)配置:
The openfire (local) config:
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,接收器)登录的。
I tested the file transfer in the local environment, one user is logged in by Simulator (Sender), the other user is logged in by Device (iPod, receiver).
-
TURNSocket.m(均已更改),更改代理
TURNSocket.m (both changed), change the proxy
+ (void)initialize {
...
proxyCandidates = [[NSMutableArray alloc] initWithObjects:@"local", nil];
...
}
在发件人和收件人身上配置
Config both on sender and receiver
- (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(发件人)
Setup and call TURNSocket (Sender)
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同时呼叫(发送方和接收方)
didSucceed called both (sender and receiver)
- (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: Received data here? (Receiver)
- (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
}
有谁知道这是什么问题?
Does anyone know what's the problem?
非常感谢!
推荐答案
要设置外部IP地址,您需要使用xmpp.proxy.externalip而不是xmpp.externalip
To set an external ip address, you need to use xmpp.proxy.externalip rather than xmpp.externalip
这篇关于XMPPFramework - TURNSocket无法接收我自己发送的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!