2

我使用 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

我在本地环境中测试了文件传输,一个用户通过模拟器(Sender)登录,另一个用户通过设备(iPod,接收器)登录。

  1. TURNSocket.m(均已更改),更改代理

    + (void)initialize {
        ...
        proxyCandidates = [[NSMutableArray alloc] initWithObjects:@"local", nil];
        ...
    }
    
  2. 在发送者和接收者上都配置

    - (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;
    }
    
  3. 设置和调用 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];
    
  4. didSucceed 同时调用了(发送者和接收者)

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

    }

  5. 发送文件?在发件人上

    - (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
    }
    

有谁知道是什么问题?

非常感谢!

4

1 回答 1

-1

设置外部ip地址,需要使用xmpp.proxy.externalip而不是xmpp.externalip

于 2012-06-12T11:59:40.900 回答