我写的代码读取数据从TCP端口的数据3000着读TCP端口
- (BOOL)connect
{
int cIter = 0;
while(cIter++<5)
{
CFReadStreamRef readStream;
CFWriteStreamRef writeStream;
@try{
CFStreamCreatePairWithSocketToHost(NULL, (__bridge CFStringRef)M_CONNECT_HOST, M_CONNECT_PORT, &readStream, &writeStream);
}
@catch (NSException *ex) {
}
if(readStream!=nil && writeStream!=nil)
{
m_sin = (__bridge NSInputStream *)readStream;
m_sout = (__bridge NSOutputStream *)writeStream;
[m_sin setDelegate:self];
[m_sout setDelegate:self];
[m_sin scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[m_sout scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[m_sin open];
[m_sout open];
return true;
}
}
return false;
}
当我写为tcp输出流的工作,但是当我尝试从TCP输入读取数据流的不读我的意思是我的 [m_sin read:t maxlength:10]; 总是返回-1(其中m_sin是我的输入流)
和IM通过终端
的数据传递到TCP端口请帮我
'[NSInputStream streamError]'返回什么? – trojanfoe
[NSInputStream streamError]返回“操作无法完成。错误的地址” – Deepak