nsstream

How to properly open and close a NSStream on another thread

浪子不回头ぞ 提交于 2019-12-07 02:13:05
问题 I have an application that connects to a server using NSStream on another thread. The application also closes the connection should the user decide to log out. The problem is that I am never able to successfully close the stream or the thread upon having the user disconnect. Below is my code sample on how I approach creating a thread for my network and trying to close the stream: + (NSThread*)networkThread { static NSThread *networkThread = nil; static dispatch_once_t onceToken; dispatch_once

I cannot initialize a NSInputStream

你说的曾经没有我的故事 提交于 2019-12-06 12:08:33
Please help me, im going insane. I need to create an NSInputStream so i can read a live preview from a camera over wifi. liveViewStream is an NSInputStream -Instance-Variable that is declared in my implementation like so: @implementation MKSonyCamHandler{ NSInputStream *liveViewStream; } liveViewURL is a valid URL that i can open in my browser when i connect to the camera's network (although i dont think that this makes any difference). I have checked that it exists, is not nil and holds the value that i expect. But when i do this: liveViewStream = [[NSInputStream alloc] initWithURL

Bonjour in the Background?

老子叫甜甜 提交于 2019-12-06 07:19:58
问题 I noticed that Pasteboard, a clipboard app for iOS, can run Bonjour service in the background. I've no idea how they implement that, so I searched on the Internet and then found that it plays a silent sound file when in background. But it is not true now, because I can't see the app icon on the iPod management screen. How could they do that? Any ideas? Thank you in advance. Kai. 回答1: You could, in theory, mark your application as needing to run in the background continuously (for VoIP, or

NSStream Handle Event Giving Status 4

守給你的承諾、 提交于 2019-12-06 02:11:18
I was trying on a TCP connection app, and I am getting a NSStreamEvent "4" on handleEvent. What am I doing wrong? My code is like, -(void) initNetworkCommunication { CFReadStreamRef readStream; CFWriteStreamRef writeStream; CFStreamCreatePairWithSocketToHost(NULL, (CFStringRef)@"localhost", 80, &readStream, &writeStream); inputStream = (__bridge_transfer NSInputStream *)readStream; outputStream = (__bridge_transfer NSOutputStream *)writeStream; [inputStream setDelegate:self]; [outputStream setDelegate:self]; [inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode

NSStream receive NSStreamEventEndEncountered during opening

别等时光非礼了梦想. 提交于 2019-12-05 22:49:25
I have a client - server app that uses NSStream to connect. sometimes when trying to open a connection, one side of the connection gets NSStreamEventEndEncountered when first trying to send a message. I use the bridge between CFStream and NSStream. My server create a socket with: _ipv4cfsock = CFSocketCreate(kCFAllocatorDefault,PF_INET, SOCK_STREAM,IPPROTO_TCP, kCFSocketAcceptCallBack, handleConnect, &info); In the handleConnect callback function, CFStreamCreatePairWithSocket is used to get two CFStream. My client use CFStreamCreatePairWithSocketToHost to connect to the host. The client

how to disable Nagle algorithm on TCP connection on iPhone

a 夏天 提交于 2019-12-04 22:45:03
问题 I'm building a socket , using CFStreamCreatePairWithSocketToHost(kCFAllocatorDefault, (CFStringRef) yourHostAsNSString, yourPortAsInteger, &myReadStream, &myWriteStream); and I see that when I send a messages with "myWriteStream" it concatenate few message together and then send them. I think it happens because of the Nagle algorithm and I want to disable it. Does any one knows how to do it? 回答1: No guarantee this will fix your problem, but if you want to disable the Nagle algorithm, you need

How to Transfer Large Files over wifi in iOS

a 夏天 提交于 2019-12-04 17:36:56
问题 I downloaded WiTap Code From Apple's website. Its for transferring data over local wifi network. I am working in a project to interact as client - server architecture. I am sending NSData from client side to server. I made 2 projects; one for client and one for server At client side project, i made following Changes For that I modified the AppController.m file by adding following method AppController.m (Client side) - (void)sendData:(NSData*)pobjData { assert(self.streamOpenCount == 2); if (

NSStream don't send all data

只愿长相守 提交于 2019-12-04 12:49:08
My case is quite strange: I practically used the example "SimpleFTPSample" (some small variation of the type [self.networkStream setProperty: (id) kCFBooleanFalse forKey: (NSString *) kCFStreamPropertyFTPAttemptPersistentConnection]; to avoid keeping the connection alive WiFi/3G) to perform transfer operations FTP file but despite not having errors of any kind, your downloaded file is corrupted if you use an ftp site: To resolve this issue, simply add a sleep (3)! This function (sleep) must be performed BEFORE [self.networkStream close]; Warning: If I change the ftp site I have no problem

Bonjour in the Background?

為{幸葍}努か 提交于 2019-12-04 11:25:28
I noticed that Pasteboard, a clipboard app for iOS, can run Bonjour service in the background. I've no idea how they implement that, so I searched on the Internet and then found that it plays a silent sound file when in background. But it is not true now, because I can't see the app icon on the iPod management screen. How could they do that? Any ideas? Thank you in advance. Kai. You could, in theory, mark your application as needing to run in the background continuously (for VoIP, or mapping). I've done something this in a proof of concept and it worked great. Alternatively, this document

Sending UIImage over NSOutputStream [closed]

谁都会走 提交于 2019-12-04 03:58:41
I'm trying to send an image that user takes to the server. I get the JPEG representation, append that to the string needed to upload the photo, and then send the data through NSOutputStream. However, when I try to get the photo back from server, I only see 10% of it from the top. Any help would be appreciated. btw. socket is open and connected. Here's my code: NSString *requestString = [NSString stringWithFormat:@"SubmitPhoto::%@::", userID]; NSData * stringData = [requestString dataUsingEncoding:NSUTF8StringEncoding]; NSData *imgData = UIImageJPEGRepresentation(image, 1.0); NSMutableData