在没有添加换行符的情况下刷新NSStream

时间:2014-09-03 11:58:00

标签: objective-c cocoa-touch nsstream

我在刷新iOS套接字客户端应用程序的输出流时遇到问题。

我需要在不添加\r\n\n的情况下刷新流。服务器不接受发送的电报中的其他字节。

有没有办法在不向发送的数据添加任何字符的情况下进行刷新?

- (void)openUsingPort: (int)param_port andIp: (NSString*)param_ip
{
     CFReadStreamRef readStream;
     CFWriteStreamRef writeStream;

     CFStreamCreatePairWithSocketToHost(NULL, (__bridge CFStringRef)param_ip, param_port,&readStream, &writeStream);

     inputStream = (__bridge NSInputStream *)readStream;
     outputStream = (__bridge NSOutputStream *)writeStream;

     [inputStream setDelegate:self];
     [outputStream setDelegate:self];


     [inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
     [outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];

     [inputStream open];
     [outputStream open];
}


-(void) sendData:(NMPCommand*) command
{
     NSString *output = [[NSString alloc] init];

     uint8_t buffer[command.infoSize+4];

     buffer[0] = command.cmd;

     buffer[1] = 1;

     buffer[2] = (command.infoSize>>8)&0xFF;
     buffer[3] = command.infoSize&0xFF;

     memcpy(buffer+4, command.rcv_info, command.infoSize);


     [outputStream write:(const uint8_t*)buffer maxLength:(command.infoSize+4)];    


     for(int i = 0;i<command.infoSize+4;i++)
     {
         output = [NSString stringWithFormat:@"%@ 0x%x", output, buffer[i]];
     }
     NSLog(@"sent data:%@",output);

}

0 个答案:

没有答案