XMPPFramework - TURNSocket收不到自己发送的数据?

发布于 2024-12-27 08:30:24 字数 2404 浏览 1 评论 0原文

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

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

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

    + (void)初始化 {
        ...
        proxyCandidates = [[NSMutableArray alloc] initWithObjects:@"local", nil];
        ...
    }
    
  2. 配置

    - (BOOL)xmppStream:(XMPPStream *)发送者 didReceiveIQ:(XMPPIQ *)iq {
    
        ...
    
        if ([TURNSocket isNewStartTURNRequest:iq]) {
    
            NSLog(@"IS NEW TURN 请求接收.. TURNSocket ..................");
    
            TURNSocket *turnSocket = [[TURNSocket alloc] initWithStream:xmppStream传入TURNRequest:iq];
            [turnSockets addObject:turnSocket];
            [turnSocket startWithDelegate:self delegateQueue:dispatch_get_main_queue()];
            [turnSocket释放];
        }
        返回是;
    }
    
  3. 设置并调用 TURNSocket(发送方)

    TURNSocket *turnSocket = [[TURNSocket alloc] initWithStream:[self xmppStream] toJID:user.primaryResource.jid];
    [turnSockets addObject:turnSocket];
    [turnSocket startWithDelegate:self delegateQueue:dispatch_get_main_queue()];
    [turnSocket释放];
    
  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"]];
    
        [套接字 writeData:dataF withTimeout:60.0f 标签:0];
    }
    

    或者:这里收到数据了吗? (接收者)

    - (void)turnSocket:(TURNSocket *)sender didSucceed:(GCDAsyncSocket *)socket {
    
        NSData *dataF = [[NSData alloc] init];
    
        [套接字 readDataToData:dataF withTimeout:30.0 标记:0];
        NSLog(@"dataF: %d", [dataF 长度]); // 数据F:0
    }
    

有谁知道问题出在哪里吗?

非常感谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

最舍不得你 2025-01-03 08:30:24

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文