Note that there are some explanatory texts on larger screens.

plurals
  1. POaccessing method from one class to another that receives message from server
    primarykey
    data
    text
    <p>i will explain the best i can if u need further explanation or detail please comment..</p> <p>I am having a local python server running on my computer that gives messages to client based on the request.</p> <p>I have a MAC client application in which i have 3 classes -</p> <ol> <li><p>Chatlogic class- this class initialises the connection and sends and receives the messages from the server.</p></li> <li><p>Login class - this maintains the login of user to the application , in this class i have a instance of the Chatlogic class, i can send messages through the object of the chatlogic class like this [chatLogicObject sendmessage:<em>something</em>]</p></li> </ol> <p>My problem is this = When ever i receive it comes in the chatLogic class instance and not in the LoginClass so i have a method called -(void)messageReceived in login class that should override the same method in the chatLogic class (But this does not work). How can i receive the method in the Loginclass ?</p> <p>To avoid confusion i have added my chatlogic class</p> <pre><code>#import &lt;Foundation/Foundation.h&gt; @interface chatLogic : NSObject &lt;NSStreamDelegate&gt; @property (copy)NSOutputStream *outputStream; @property (copy)NSInputStream *inputStream; @property (copy)NSString *streamStatus; -(void)initNetworkCommunications; -(void)sendMessage:(id)sender; -(void)stream:(NSStream *)aStream handleEvent:(NSStreamEvent)streamEvent; -(void)messageReceived:(NSString*)message; //i want this method to be used in some other classes @end </code></pre> <p>The implementation file is as follows</p> <h1>import "chatLogic.h"</h1> <p>@implementation chatLogic</p> <p>@synthesize inputStream ; @synthesize outputStream ; @synthesize streamStatus;</p> <p>-(id)init{</p> <pre><code>if (self == [super init]) { } return self; </code></pre> <p>}</p> <p>-(void)initNetworkCommunications{</p> <pre><code>CFReadStreamRef readStream; CFWriteStreamRef writeStream; CFStreamCreatePairWithSocketToHost(NULL, (CFStringRef)@"192.168.1.22", 80, &amp;readStream, &amp;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]; </code></pre> <p>}</p> <p>-(void)stream:(NSStream *)aStream handleEvent:(NSStreamEvent)streamEvent{</p> <pre><code>switch (streamEvent) { case NSStreamEventOpenCompleted: NSLog(@"Stream opened"); streamStatus = [[NSString alloc]initWithFormat:@"Stream opened"]; break; case NSStreamEventHasBytesAvailable: if (aStream == inputStream) { uint8_t buffer[1024]; int len; while ([inputStream hasBytesAvailable]) { len = (int)[inputStream read:buffer maxLength:sizeof(buffer)]; if (len &gt; 0) { NSString *output = [[NSString alloc]initWithBytes:buffer length:len encoding:NSASCIIStringEncoding]; if (nil != output) { NSLog(@"server said: %@",output); [self messageReceived:output]; } } } } case NSStreamEventErrorOccurred: { NSLog(@"cannot connect to the host!"); break; } case NSStreamEventEndEncountered: { break; } default: { NSLog(@"unknown event!!"); } } </code></pre> <p>}</p> <p>-(void)sendMessage:(id)sender{</p> <p>}</p> <p>-(void)messageReceived:(NSString*)message{</p> <pre><code>NSLog(@"the received message in chat logic class"); </code></pre> <p>}</p> <p>-(void)dealloc{</p> <pre><code>[inputStream close]; [outputStream close]; [inputStream release]; [outputStream release]; [super dealloc]; </code></pre> <p>}</p> <p>@end</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload