XMPPFramework - TURNSocket can't receive the data that sent by myself?

扶醉桌前 提交于 2019-12-06 11:04:36

问题


I used the openfire as the xmpp server, and want to transfer file via the Turnsocket.

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

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).

  1. TURNSocket.m (both changed), change the proxy

    + (void)initialize {
        ...
        proxyCandidates = [[NSMutableArray alloc] initWithObjects:@"local", nil];
        ...
    }
    
  2. 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;
    }
    
  3. 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];
    
  4. didSucceed called both (sender and receiver)

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

    }

  5. Send a file? on sender

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

Thanks very much!


回答1:


To set an external ip address, you need to use xmpp.proxy.externalip rather than xmpp.externalip



来源:https://stackoverflow.com/questions/8877864/xmppframework-turnsocket-cant-receive-the-data-that-sent-by-myself

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!