• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to interrupt a function
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to interrupt a function


  • Subject: Re: How to interrupt a function
  • From: Andrea Salomoni <email@hidden>
  • Date: Wed, 30 Nov 2005 17:27:18 +0100

Thank you J oar,

I'm trying to use the small socket class to connect to a server with a static ip.
All works fine until (for some problem) the server will go down.
if the server is down the method [socket connectToHostName:host port:port]; returns false, but the GUI is not available (while isn't multithread app and the socket blocking is set on YES.).
So i decided to start some thread in this way:


-(BOOL)startConnection
{
NSAutoreleasePool * firstThreadPool = [[NSAutoreleasePool alloc]init];
if (!socket)
	{
	socket = nil;
	int port = 4321;
	NSString * host = [NSString stringWithString:IPUSA];
	socket = [Socket socket];
	[socket setBlocking:YES];

	//////
	//try to connect
	[socket connectToHostName:host port:port];

	if ([socket isConnected])
		{
		NSLog  (@"socket connected");
		[self setStatus:YES];
		return YES;
		}
	else
		{
		NSLog  (@"impossible to connect");
		[self setStatus:NO];
		return NO;
		}
	}
	[self setStatus:NO];
	return NO;
[firstThreadPool release];

}

If the socket isn't created I need to stop the execution and return an error...
How can I do?


Thank you a lot for support
Andrea


Il giorno 30/nov/05, alle ore 17:04, j o a r ha scritto:


On 30 nov 2005, at 15.39, Andrea Salomoni wrote:

the problem is the secondary thread...

There are a couple of problems in this code Andrea. But to focus on the thing you ask about; it's likely that the error message you see ("*** Uncaught exception: <Socket: Not connected> Socket: Not connected") is generated by an exception thrown by the "connectToHostName:port:" method. In that case you would need to learn about "exception guards / handlers".


j o a r




_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: How to interrupt a function
      • From: j o a r <email@hidden>
References: 
 >How to interrupt a function (From: Andrea Salomoni <email@hidden>)
 >Re: How to interrupt a function (From: Colin Barrett <email@hidden>)
 >Re: How to interrupt a function (From: Andrea Salomoni <email@hidden>)
 >Re: How to interrupt a function (From: j o a r <email@hidden>)

  • Prev by Date: Re: Finding the error...
  • Next by Date: Re: Subclassing NSMutableDictionary
  • Previous by thread: Re: How to interrupt a function
  • Next by thread: Re: How to interrupt a function
  • Index(es):
    • Date
    • Thread