我想使用下面的代碼來捕獲.NET服務器的響應。Asyncsocket iPhone讀取數據
做一個telnet測試工作(我得到的迴應);但是,使用此代碼,我沒有得到迴應。
-(IBAction)connectClicked:(id)sender {
if (![socket connectToHost:@"192.168.100.192" onPort:1337 error:nil]) {
NSLog(@"connection failed");
}
}
-(IBAction)fireClicked:(id)sender {
NSString *welcomeMsg = @"GetId";
NSData *welcomeData = [welcomeMsg dataUsingEncoding:NSUTF8StringEncoding];
[socket writeData:welcomeData withTimeout:-1 tag:0];
NSLog(@"message sent!");
}
- (void)onSocket:(AsyncSocket *)sock didConnectToHost:(NSString*)host port:(UInt16)port {
NSLog(@"onSocket:%p didConnectToHost:%@ port:%hu", sock, host, port);
[sock readDataToData:[AsyncSocket CRLFData] withTimeout:-1 tag:0];
}
-(void) onSocket:(AsyncSocket *)sock didReadData:(NSData*)data withTag:(long)tag {
NSLog(@"onSocket:%p didReadData:%i", tag);
[sock readDataToData:[AsyncSocket CRLFData] withTimeout:-1 tag:0];
}
- (void)onSocket:(AsyncSocket *)sock didWriteDataWithTag:(long)tag {
NSLog(@"onSocket:didWriteDataWithTag:%i", tag);
[sock readDataToData:[AsyncSocket CRLFData] withTimeout:-1 tag:0];
}
我得到與服務器的連接,我可以將信息發送到服務器,但我沒有得到答覆。
這就是我在日誌中得到的;
2011-03-21 10:00:32.424 CtC[33521:207] onSocket:0x4c3ebc0 didConnectToHost:192.168.100.192 port:1337
2011-03-21 10:00:35.846 CtC[33521:207] message sent!
爲什麼我沒有收到回覆?
嗨安迪!謝謝你的支持! - 我更新了我的問題......但它仍然不起作用......你可以看看嗎?謝謝! – Derk 2011-03-21 08:59:12
正如Suprie所提到的,您必須確保服務器端知道您的來電結束時間(Enter,CTRL-D等)。否則,.Net服務器可能只是坐在那裏等待進一步的輸入。 – 2011-03-21 15:14:51
嗨安迪! .net服務器會發送命令回iphone應用程序.... – Derk 2011-03-22 13:23:15