【发布时间】:2012-02-11 06:25:14
【问题描述】:
我用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(Sender)登录,另一个用户通过Device(iPod,receiver)登录。
-
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 (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 同时调用(发送者和接收者)
- (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]; }或者:这里接收到数据? (接收者)
- (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 }
有谁知道问题出在哪里?
非常感谢!
【问题讨论】:
-
嗨,尼尔。你在这方面有什么进展吗?
-
你是如何传输文件的?
-
如果发送文件有任何进展,请告诉我
-
尼尔,有没有为你调用 didSucceed ?如果是的话,请告诉我你是怎么做到的。提前致谢。
标签: ios xmpp file-transfer xmppframework