New To Mac-Forums?

Welcome to our community! Join the discussion today by registering your FREE account. If you have any problems with the registration process, please contact us!

Get your questions answered by community gurus Advice and insight from world-class Apple enthusiasts Exclusive access to members-only contests, giveaways and deals

Join today!

Start a Discussion

Mac-Forums Brief

Subscribe to Mac-Forums Brief to receive special offers from Mac-Forums partners and sponsors

Join the conversation RSS
OS X - Development and Darwin Discussion and questions about development for Mac OS X.

Question about Input/Output Streams (sockets)

Post Reply New Thread Subscribe

Thread Tools

Member Since: Dec 30, 2008
Posts: 14
mjparme is on a distinguished road

mjparme is offline
If I open a network connection with the code below do I need to do anything special to keep the program running? It is opening the streams, but then the program just exits. Do I need to fire up a thread or something?

All I am trying to do is connect to on port 13. All that server does is print out the time and then disconnect. My stream:handleEvent: delegate isn't even getting called.

-(void)connectToHost {
	NSLog(@"in connect to host!");
	[NSStream getStreamsToHost:host port:13 inputStream:&iStream outputStream:&oStream];
	[iStream retain];
	NSLog(@"istream = %@",iStream);
	[oStream retain];	
	[iStream setDelegate:self];	
	[oStream setDelegate:self];	
	[iStream scheduleInRunLoop:[NSRunLoop currentRunLoop]	 
		[oStream scheduleInRunLoop:[NSRunLoop currentRunLoop]	 
	[iStream open];	
	[oStream open];

- (void)stream:(NSStream *)stream handleEvent:(NSStreamEvent)eventCode {
	NSLog(@"in handleEvent, eventcode = %i", eventCode);
    switch(eventCode) {			
        case NSStreamEventHasBytesAvailable:  {
			NSLog(@"in has bytes");
            if(!data) {				
                data = [[NSMutableData data] retain];				
            uint8_t buf[1024];			
            unsigned int len = 0;			
            len = [(NSInputStream *)stream read:buf maxLength:1024];
            if(len) {				
                [data appendBytes:(const void *)buf length:len];
				NSLog(@"len: %i", len);
                //[bytesRead setIntValue:[bytesRead intValue]+len];				
            } else {				
                NSLog(@"no buffer!");				
The output of my code (not all the code that produces this output is shown):

2009-01-08 00:25:00.878 StreamTester[25503:10b] Starting StreamTester...
2009-01-08 00:25:01.086 StreamTester[25503:10b] Hostname = <NSHost 0x1072e0> (<CFArray 0x107220 [0xa041c1a0]>{type = mutable-small, count = 2, values = (
0 : <CFString 0x107b60 [0xa041c1a0]>{contents = ""}
1 : <CFString 0x1076a0 [0xa041c1a0]>{contents = "time-a"}
)} <CFArray 0x107200 [0xa041c1a0]>{type = mutable-small, count = 1, values = (
0 : <CFString 0x1072b0 [0xa041c1a0]>{contents = ""}
2009-01-08 00:25:01.087 StreamTester[25503:10b] in connect to host!
2009-01-08 00:25:01.091 StreamTester[25503:10b] istream = <NSCFInputStream: 0x108050>
The Debugger has exited with status 0.

Have mercy on me I am a better than average Java programmer, but total newb for Objective-C and Cocoa:-)
QUOTE Thanks

SpaceTeaBoo's Avatar
Member Since: Jan 07, 2009
Location: USA
Posts: 4
SpaceTeaBoo is on a distinguished road
Mac Specs: SpaceTeaBoo

SpaceTeaBoo is offline

I want to know how to set my Photo as avatar. But I have some troubles when try to upload photo.
Some times photo does not upload. Or when I upload the photo, it has deformation.
What should I do to fix that?

Thanks for help
QUOTE Thanks

SpaceTeaBoo's Avatar
Member Since: Jan 07, 2009
Location: USA
Posts: 4
SpaceTeaBoo is on a distinguished road
Mac Specs: SpaceTeaBoo

SpaceTeaBoo is offline
Hi guys

Can you help me. I have troubles with your web site. It it works not fast.
Can somebody help me to solve the problem or explain why it can be so?

Thanks a lot
QUOTE Thanks

Post Reply New Thread Subscribe

« terminal fonts in mac | Warning :suggest parentheses around assignment used as truth value »
Thread Tools

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Starter
Last Post
The QUESTION Game ToddG Schweb's Lounge 159 08-15-2007 05:25 PM
Boot-Up Question Mark Folder Impending Doom Question. bingwalker OS X - Operating System 3 07-10-2007 05:19 AM
Ask 'me' a question... eric Schweb's Lounge 22 01-12-2007 06:33 AM
Video production question macinsandiego Movies and Video 4 11-17-2004 07:39 AM
Postscript question battleangel444 OS X - Operating System 2 07-09-2004 12:45 PM

All times are GMT -4. The time now is 09:32 PM.

Powered by vBulletin
Copyright ©2000 - 2015, Jelsoft Enterprises Ltd.

Welcome to

Create your username to jump into the discussion!

New members like you have made this community the ultimate source for your Mac since 2003!

(4 digit year)

Already a member?