GCDAsyncSocket并发送SIP数据包

时间:2013-01-07 20:14:11

标签: iphone cocoa sockets gcdasyncsocket

我尝试将INVITE发送到SIP服务器:

        GCDAsyncSocket *outgoingCallSocket = [[GCDAsyncSocket alloc] initWithDelegate:self delegateQueue:socketOutgoingCallQueue];

        BOOL result = [outgoingCallSocket connectToHost:currentSoftswitch.ip onPort:5060 error:&error];

里面

- (void)socket:(GCDAsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag

然后,当socket连接时:

- (void)socket:(GCDAsyncSocket *)sock didConnectToHost:(NSString *)host port:(uint16_t)port;
{
    NSLog(@"Connected socket to %@:%hu", host, port);
    [sock writeData:finalData withTimeout:-1 tag:OUTGOING_CALL];
    NSLog(@"\n===================SEND START TO currentSoftswitch.ip->%@:5060 =================\n%@\n===================SEND FINISH=================\n",host,[[NSString alloc] initWithData:finalData encoding:NSUTF8StringEncoding]);

这是结果:

> ===================SEND START TO currentSoftswitch.ip->195.26.84.147:5060 ================= INVITE
> sip:380442399740@91.224.223.42;transport=tcp;lr SIP/2.0 Via:
> SIP/2.0/TCP 195.26.84.147:5060;rport;lr SIP/2.0 Max-Forwards: 70 From:
> "alex@ixc.ua"
> <sip:897542@91.224.223.42>;tag=Ztr3.0MabqPlVkNJHHVdvAdeNGUXsz8E To:
> sip:380442399740@195.26.84.147 Contact: "alex@ixc.ua"
> <sip:897542@10.129.244.143:5060;transport=TCP;ob> Call-ID:
> zu.MBTPcv87dylX2i-BsA.b551Kyflic CSeq: 25575 INVITE Route:
> <sip:195.26.84.147;transport=tcp;lr> Route: <sip:195.26.84.147;lr>
> Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, SUBSCRIBE, NOTIFY,
> REFER, MESSAGE, OPTIONS Supported: replaces, 100rel, timer, norefersub
> Session-Expires: 1800 Min-SE: 90 User-Agent: CallsFreeCalls
> SSContent-Type: application/sdp Content-Length: 480
> 
> v=0 o=- 3566574154 3566574154 IN IP4 46.211.183.202 s=pjmedia c=IN IP4
> 46.211.183.202 b=AS:84 t=0 0 a=X-nat:6 m=audio 40000 RTP/AVP 104 18 108 3 8 0 96 c=IN IP4 46.211.183.202 b=TIAS:64000 a=rtcp:40001 IN IP4
> 46.211.183.204 a=sendrecv a=rtpmap:104 SILK/8000 a=fmtp:104 useinbandfec=0 a=rtpmap:18 G729/8000 a=rtpmap:108 iLBC/8000 a=fmtp:108
> mode=30 a=rtpmap:3 GSM/8000 a=rtpmap:8 PCMA/8000 a=rtpmap:0 PCMU/8000
> a=rtpmap:96 telephone-event/8000
> 
> ===================SEND FINISH=================

但是当我检查whireshark时,数据包不会像SIP那样检测到。哪里我错了?

enter image description here

1 个答案:

答案 0 :(得分:0)

简单的答案 - 错误的内容长度!