Re: Small sockets, Autorelease etc...
Re: Small sockets, Autorelease etc...
- Subject: Re: Small sockets, Autorelease etc...
- From: Brendan Younger <email@hidden>
- Date: Sun, 26 May 2002 14:27:15 -0500
Every thread in a Cocoa application must have an NSAutoreleasePool in
place at all times. The function NSApplicationMain() sets this up for
you and calls NSApplication's -run method. You *could* make your
application work by placing "NSAutoreleasePool* pool =
[[NSAutoreleasePool alloc] init]" as the very first line in your main()
function, but this is VERY BAD FORM(tm). If you want something done
when your application starts up, instanciate a new class in your
MainMenu.nib file, make it the NSApplication's delegate and implement
-applicationDidFinishLaunching: (see the docs for NSApplication).
Better yet, you could (in about 5 minutes) hook up this code to be the
action of a button in a window and have all your debugging info
displayed right in that window (no NSLog's needed).
Brendan Younger
P.S. If you just want a low-overhead testing project, just make a
Foundation tool.
On Sunday, May 26, 2002, at 01:54 PM, malcom wrote:
I'm a cocoa newbie... I would to make an irc client using cocoa and
obj-c. I
have downloaded SmallSockets framework from sourceforge.net.
This is the code to connect. I send a initial authenticatin message for
now.
But there are some problems:
- some cocoa errors;
- the result message will be visibile only when the connection timed
out by
server.
<snip>
This is the main.c code:
*********************************************
#import <Cocoa/Cocoa.h>
#import "Socket.h"
int main(int argc, const char *argv[])
{
Socket *socket;
NSString *stringa;
NSMutableData* response;
NSString* responseString;
NS_DURING
stringa = [NSString stringWithFormat:@"NICK daniele\n\rUSER dani . .
:ciao"];
socket = [Socket socket];
socket = [[Socket alloc] init];
[socket connectToHostName: @"irc.edisontel.it" port: 6667];
[socket writeString: stringa];
response = [[[NSMutableData alloc] init] autorelease];
// [socket readData:response];
/* while ( [socket readData:response] )
{
// Read until other side disconnects
}*/
[socket readData:response];
responseString = [[[NSString alloc] initWithData:response
encoding:[NSString defaultCStringEncoding]]
autorelease];
NSLog(@"data: %s",responseString);
NS_HANDLER
NS_ENDHANDLER
return NSApplicationMain(argc, argv);
}
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.