0

i have network layer written in objectiv-c for the watchOS. writing a json string on NSOutPutStream is not working, but the same thing is working in iOS project.

//writing json string on writeStream

NSString *sendString = @"{\"msg.type\":\"Connection\",\"source.address\":\"192168.0.146\"}"
const uint8_t *rawString = (const unit8_t *)[sendString UTF8String];
NSUInteger sendLength = [sendString lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
[self.writeStream write:rawString maxLength:sendLength];

if (self.writeStream.streamError != nil){
     NSLog(@"%@", self.writeStream.streamError);
} 

error printing in console:

Error Domain=NSPOSIXErrorDomain Code=9 "Bad file descriptor" UserInfo={_KCFStreamErrorCodeKey=9, _KCFStreamErrorDomainKey=1}

//setting up read & write streams

CFReadStreamRef cfReadStream;
CFWriteStreamRef cfwriteStream;

CFStreamCreatePairwithSocketToHost(KCFAllocatorDefault, (bridge CFStringRef)self.hostAddress, (intiportNumber, &cfRoadStream, &cfwritestream);


if (cfReadStream && cfwriteStream)

CFReadStreamSetProperty(ofReadStream,KCFStreamPropertyShouldCloseNativeSocket, kCFBooleanTrue);

CFWriteStreamSetProperty(cfwriteStream, KCFStreamPropertyShouldCloseNativeSocket, kCFBooleanTrue);

self.readStream = (NSInputStream)CFBridgingRelease(cfReadStream); 
[self.readStream setDelegate:self]; 
[self.readStream scheduleInRunLoop: [NSRunLoop currentRunLoop]forMode: NSDefaultRunLoopMode];
[self.readStream open];

[self.writeStream setDelegate:self];
self.writeStream = (NSOutputStream *)CFBridgingRelease (cfWriteStream); 
[self.writeStream scheduleInRunLoop: [NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopModel];
[self.writestream open];
Code cracker
  • 3,105
  • 6
  • 37
  • 67

0 Answers0