objective c - socket communication at separate thread -


I've already read about 40 pages threading, but still I'm not sure about my case. An NSObject, which opens a socket connection on a device. This object handles all communications, sending and receiving messages and so on. I would like that this stuff works on different threads. I tried to do something like this:

  - Connect: (ID) sender {SocketConnectionController * sock = [SocketConnectionController new]; [[SOCK IN WITH WITH PARAMES: IP.Text: Port.Text Etc.) Selector background: @sillector (Initvith Parama: :) with object: Nile]; Send [[SOCKETNECONNECTION CONTROLLER INSTANCE] COMMOD: GEEEIDIDIT];   

}

As you see, I am sending some messages using the current example of socket condensation controller, but it does not send anything, maybe my There is some leak to understand the side, that the connection is open due to flashing light on the device. Am I making thread on the right track? If so, how can I use it?

Update 1: I tried to do something like this:

  NSOperationQueue * queue = [NSOperationQueue new]; Socket connection * sock = [socket connection new]; [Add quote operation: sock];   

But on the CPU graph, I see that the stuff is still running on thread 1 (mainstay). What am I doing wrong?

Update 2 I came to know that the run loop, which I still need to run on main thread for input and output stream. NSDefaultRunLoopMode];

This is the reason that Update Code of 1 does not work, then I need to create a new thread for this thread and then a new run loop. It can not be done automatically by coca-framework, such as before the code (Exhibitor Aikgraund).

I found a way to make socket connections on different threads:

  NSThread * nThread; - (NSThread *) NetworkTrade {nThread = Zero; NThread = [[NSThread alloc] initWithTarget: auto selector: @selector (networkThreadMain :) object: zero]; [Nthread start]; NSLog (@ "Thread:% @, debug details:% @", NTTrade, NTTrade.Debug Description); Return nThread; } - (zero) NetworkTuffman: (id) run unused {do {[NSRunLoop currentRunLoop]]; } While (yes); } - (zero) timetit date: (id) unused {[Input stream schedule unbalanced: [NSRON loop currentRun loop] formad: NSRON loop commonmodes]; [OutputStream Schedule Anatolup: [NSRunLoop currentRunLoop] forMode: NSRunLoopCommonModes]; } - (BOOL) Connect with error: (NSString **) e {CFReadStreamRef readStream; CFWriteStreamRef WriteStream; CFStreamCreatePairWithSocketToHost (NULL, (CFStringRef) @ "127.0.0.1", [server port], read more stream, and write stream); Inputstream = (__breeze NSInputStream *) readStream; Outputstream = (__bridge NSOutputStream *) writestream; [InputTermSetial: Self]; [OutputStream Settlement: Self]; [Self display selector: @sillector (schedule indexcompany thread) on thread: [self networktred] with object: wait until zero: yes]; [Open inputstream]; [Open the output stream]; }   

You only need to input this code in the new class type NSThread

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -