iPhone SDK中的XMPP发送/接收文件...? [英] XMPP Sending/Receving file in iphone sdk ...?

查看:99
本文介绍了iPhone SDK中的XMPP发送/接收文件...?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用XMPP框架在iPhone SDK中发送/接收文件? 目前,我正在使用XEP-0065类,并使用以下代码:

How to send/receive file in iphone sdk using xmpp framework ? Currently i am using XEP-0065 classes, and use the following code:

ObjTURNSocket = [[TURNSocket alloc] initWithStream:((TestAppDelegate*)[[UIApplication sharedApplication] delegate]).xmppStream 
                                                 toJID:chatuser.jid];
    [ObjTURNSocket start:self];

我从服务器收到以下响应:

And I am getting following response from the server:

<iq type="error" id="AB2ED567-B97F-4DFE-B789-7731A617C239" to="kapil@testweb/6df6dc96" from="jabber.org">
   <query xmlns="http://jabber.org/protocol/disco#items"/>
   <error code="404" type="cancel">
      <remote-server-not-found xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/>
   </error>
 </iq>`

任何帮助或建议将不胜感激.

Any help or suggestion will be well appreciated.

推荐答案

首先,使用可能用于代理的一系列可能的服务器调用setProxyCandidates.默认值为"jabber.org",并且您的服务器未与jabber.org联合,这就是为什么您会收到迪斯科错误的原因.

First, call setProxyCandidates with an array of the possible servers that you might be able to use for proxying. The default is "jabber.org", and your server is not federated with jabber.org, which is why you are getting the disco error back.

接下来,在您的委托中,实现以下方法:

Next, in your delegate, implement the following methods:

- (void)turnSocket:(TURNSocket *)sender didSucceed:(GCDAsyncSocket *)socket;
- (void)turnSocketDidFail:(TURNSocket *)sender;

然后,在您的didSucceed实现中,使用以下命令在传入的套接字上发送数据:

Then, in your didSucceed implementation, send data on the socket that was passed in, using:

- (void)writeData:(NSData *)data 
      withTimeout:(NSTimeInterval)timeout 
              tag:(long)tag;

最后,关闭插座:

- (void)disconnectAfterWriting;

我通过查看[delegate以查找委托被调用的位置.这使我回到 TURNSocket.h ,其中记录了供委托人实施的协议.

I figured this out by looking at the source for TURNSocket.m, looking for the hardcoded "jabber.org", then searching for [delegate to find the places the delegate was getting called. This took me back to TURNSocket.h, which had a protocol documented for the delegate to implement.

这篇关于iPhone SDK中的XMPP发送/接收文件...?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆