我是iOS和Objective C的新手...... 在我的應用程序中,我正在使用CFStream建立到我的服務器的套接字連接..問題是當我運行我的時候我的服務器是 程序使用本地IP(192.168.10.246)連接建立,但當我用公共IP替換它的視圖相當凍結,並給出以下錯誤事件..使用公共ip時CFStream連接無法連接
我目前正在模擬器上運行...
2013-06-27 12:50:41.778 BarcodeGenerator[446:c07] Start StreamEvent 8
2013-06-27 12:50:41.778 BarcodeGenerator[446:c07] Can not connect to the host!
2013-06-27 12:50:41.779 BarcodeGenerator[446:c07] Start StreamEvent 8
2013-06-27 12:50:41.780 BarcodeGenerator[446:c07] Can not connect to the host!
而且我的代碼..
CFReadStreamRef readStream;
CFWriteStreamRef writeStream;
CFStreamCreatePairWithSocketToHost(NULL, (CFStringRef)ip, 54000, &readStream, &writeStream);
inputStream = (NSInputStream *)readStream;
outputStream = (NSOutputStream *)writeStream;
[inputStream setDelegate:self];
[outputStream setDelegate:self];
[inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[inputStream open];
[outputStream open];
NSData *data = [[NSData alloc] initWithData:[pinno dataUsingEncoding:NSASCIIStringEncoding]];
[outputStream write:[data bytes] maxLength:[data length]];
[outputStream close];
我是否需要添加一些額外的代碼段用於公網IP ...或者是某種網絡連接的防火牆問題或在Xcode中設置的??? 請幫忙!!!!
Edit:
我重視Wireshark的日誌: 我的目的地公網IP是221.135.139.46 ....
No. Time Source Destination Protocol Length Info
83 2.426998000 192.168.43.131 221.135.139.46 TCP 78 50853 > 54000 [SYN] Seq=0 Win=65535 Len=0 MSS=1460 WS=16 TSval=61451776 TSecr=0 SACK_PERM=1
Frame 83: 78 bytes on wire (624 bits), 78 bytes captured (624 bits) on interface 0
Ethernet II, Src: Apple_13:f4:a1 (00:23:12:13:f4:a1), Dst: SamsungE_75:d9:c7 (94:63:d1:75:d9:c7)
Internet Protocol Version 4, Src: 192.168.43.131 (192.168.43.131), Dst: 221.135.139.46 (221.135.139.46)
Transmission Control Protocol, Src Port: 50853 (50853), Dst Port: 54000 (54000), Seq: 0, Len: 0
我只是檢查我的防火牆設置...我的防火牆是關閉...你能告訴我任何已知的公網IP的,我可以測試我的連接 – Audi
您需要轉發的連接,您使用的什麼路由器/防火牆? –
我正在使用我的辦公室網...所以我認爲它可能受到某些防火牆的保護,不允許建立任何公共連接......但後來我通過我的個人數據卡網絡嘗試......但仍然沒有運氣......我已經在android中使用套接字連接實現相同的副本...它工作正常...不知道關於iOS – Audi