Index: cotvnc/Chicken.xcodeproj/project.pbxproj
===================================================================
--- cotvnc/Chicken.xcodeproj/project.pbxproj	(revision 798)
+++ cotvnc/Chicken.xcodeproj/project.pbxproj	(working copy)
@@ -1579,7 +1579,7 @@
 			buildSettings = {
 				GCC_OPTIMIZATION_LEVEL = 0;
 				GCC_VERSION = 4.0;
-				SDKROOT = /Developer/SDKs/MacOSX10.4u.sdk;
+				SDKROOT = /Developer/SDKs/MacOSX10.5.sdk;
 				ZERO_LINK = NO;
 				_CHICKEN_VERSION_ = 2.2b2;
 			};
Index: cotvnc/Source/MyApp.h
===================================================================
--- cotvnc/Source/MyApp.h	(revision 798)
+++ cotvnc/Source/MyApp.h	(working copy)
@@ -11,4 +11,6 @@
 
 @interface MyApp : NSApplication
 
+
+
 @end
Index: cotvnc/Source/MyApp.m
===================================================================
--- cotvnc/Source/MyApp.m	(revision 798)
+++ cotvnc/Source/MyApp.m	(working copy)
@@ -93,4 +93,6 @@
 	[super sendEvent: anEvent];
 }
 
+
+
 @end
Index: cotvnc/Source/RFBConnectionManager.h
===================================================================
--- cotvnc/Source/RFBConnectionManager.h	(revision 798)
+++ cotvnc/Source/RFBConnectionManager.h	(working copy)
@@ -19,6 +19,7 @@
 #import <AppKit/AppKit.h>
 #import "ServerDataViewController.h"
 #import "ConnectionWaiter.h"
+#import "Session.h"
 
 @class Profile, ProfileManager;
 @class RFBConnection;
@@ -93,4 +94,6 @@
 - (BOOL)launchedByURL;
 - (void)setLaunchedByURL:(bool)launchedByURL;
 
+- (Session*)getSession:(id<IServerData>)server;
+
 @end
Index: cotvnc/Source/RFBConnectionManager.m
===================================================================
--- cotvnc/Source/RFBConnectionManager.m	(revision 798)
+++ cotvnc/Source/RFBConnectionManager.m	(working copy)
@@ -436,8 +436,8 @@
 	if ( 0 == [sessions count] ) {
         if ( mRunningFromCommandLine ) 
             [NSApp terminate:self];
-        else
-            [self showConnectionDialog:nil];
+        //else
+			//[self showConnectionDialog:nil];
     }
 }
 
@@ -687,4 +687,20 @@
 	mLaunchedByURL = launchedByURL;
 }
 
+- (Session*)getSession:(id<IServerData>)server
+{
+	Session* result = nil;
+	
+	NSEnumerator *enumerator = [sessions objectEnumerator];
+    Session      *session;
+	
+	while (session = [enumerator nextObject]) {
+		if ([session getServer] == server) {
+			result = session;
+			break;
+		}
+	}
+	return result;
+}
+
 @end
Index: cotvnc/Source/Session.h
===================================================================
--- cotvnc/Source/Session.h	(revision 798)
+++ cotvnc/Source/Session.h	(working copy)
@@ -101,6 +101,8 @@
 - (void)setNewTitle:(id)sender;
 
 - (IBAction)requestFrameBufferUpdate:(id)sender;
+- (id<IServerData>)getServer;
+- (void)makeKeyAndOrderFront;
 
     //window delegate messages
 - (void)windowDidBecomeKey:(NSNotification *)aNotification;
Index: cotvnc/Source/Session.m
===================================================================
--- cotvnc/Source/Session.m	(revision 798)
+++ cotvnc/Source/Session.m	(working copy)
@@ -253,7 +253,7 @@
 				NSBeginAlertSheet(header, okayButton, supportReconnect ? reconnectButton : nil, nil, window, self, @selector(connectionTerminatedSheetDidEnd:returnCode:contextInfo:), nil, nil, aReason);
 			}
         } else {
-            [[RFBConnectionManager sharedManager] removeConnection:self];
+            //[[RFBConnectionManager sharedManager] removeConnection:self];
         }
     }
 }
@@ -496,6 +496,14 @@
 {
     [connection requestFrameBufferUpdate:sender];
 }
+- (id<IServerData>)getServer
+{
+	return server_;
+}
+- (void)makeKeyAndOrderFront
+{
+	[window makeKeyAndOrderFront:self];
+}
 
 - (void)sendCmdOptEsc: (id)sender
 {
Index: cotvnc/Source/ListenerController.m
===================================================================
--- cotvnc/Source/ListenerController.m	(revision 798)
+++ cotvnc/Source/ListenerController.m	(working copy)
@@ -275,7 +275,12 @@
     NSFileHandle * incomingConnection = [[aNotification userInfo] objectForKey:NSFileHandleNotificationFileHandleItem];
     ServerFromConnection    *server;
 
-    [self stopListener];
+	if (listeningSockets[0])
+		[listeningSockets[0] acceptConnectionInBackgroundAndNotify];
+	if (listeningSockets[1])
+		[listeningSockets[1] acceptConnectionInBackgroundAndNotify];
+    //[self stopListener];
+	
     
     RFBConnectionManager* cm = [RFBConnectionManager sharedManager];
     server = [[ServerFromConnection alloc] initFromConnection:incomingConnection];
Index: cotvnc/Source/AppDelegate.h
===================================================================
--- cotvnc/Source/AppDelegate.h	(revision 798)
+++ cotvnc/Source/AppDelegate.h	(working copy)
@@ -7,12 +7,14 @@
 //
 
 #import <Cocoa/Cocoa.h>
+#import "ConnectionWaiter.h"
 
-
-@interface AppDelegate : NSObject {
+@interface AppDelegate : NSObject<ConnectionWaiterDelegate> {
 	IBOutlet NSMenuItem *mRendezvousMenuItem;
 	IBOutlet NSTextField *mInfoVersionNumber;
     IBOutlet NSMenuItem *fullScreenMenuItem;
+	
+	NSMenu* dockMenu;
 }
 
 - (IBAction)showPreferences: (id)sender;
@@ -25,4 +27,9 @@
 
 - (NSMenuItem *)getFullScreenMenuItem;
 
+- (NSMenu *)applicationDockMenu:(NSApplication *)sender;
+- (void)connectionSucceeded: (RFBConnection *)theConnection;
+- (void)connectionFailed;
+- (void)applicationWillTerminate:(NSNotification *)aNotification;
+
 @end
Index: cotvnc/Source/AppDelegate.m
===================================================================
--- cotvnc/Source/AppDelegate.m	(revision 798)
+++ cotvnc/Source/AppDelegate.m	(working copy)
@@ -12,6 +12,7 @@
 #import "ProfileManager.h"
 #import "RFBConnectionManager.h"
 #import "ListenerController.h"
+#import "ServerDataManager.h"
 
 
 @implementation AppDelegate
@@ -120,4 +121,65 @@
     return fullScreenMenuItem;
 }
 
+- (NSMenu *)applicationDockMenu:(NSApplication *)sender
+{
+
+	if ( dockMenu == nil)
+		[dockMenu release];
+	
+	dockMenu = [[[NSMenu alloc] init] retain];
+	
+	ServerDataManager* serverManager = [ServerDataManager sharedInstance];
+	
+	[dockMenu addItemWithTitle:@"Connect to"
+						action:nil
+				 keyEquivalent:@""];
+	for (NSString* s in [serverManager sortedServerNames]) {
+
+		
+		NSMenuItem* item =  [dockMenu addItemWithTitle:s
+												action:@selector(connectClicked:)
+										 keyEquivalent:@""];
+		
+		[item setTarget:self];
+
+	}
+
+    return dockMenu;
+}	
+
+- (void)connectClicked: (id)sender
+{
+	ServerDataManager* serverManager = [ServerDataManager sharedInstance];
+	id<IServerData> server = [serverManager getServerWithName:[sender title]];
+	
+	Session* session = [[RFBConnectionManager sharedManager] getSession:server];
+	if (session) {
+		[session makeKeyAndOrderFront];
+	} else {
+		[[ConnectionWaiter waiterForServer:server delegate:self window:nil] retain];		
+	}
+	
+	[NSApp activateIgnoringOtherApps:YES];
+				  
+}
+
+- (void)connectionSucceeded: (RFBConnection *)theConnection
+{
+	[[RFBConnectionManager sharedManager] successfulConnection:theConnection];
+}
+
+- (void)connectionFailed
+{
+	NSLog(@"Failed to connect");
+}
+
+- (void)applicationWillTerminate:(NSNotification *)aNotification
+{
+	if ( dockMenu == nil)
+		[dockMenu release];
+	
+}
+
+
 @end
Index: cotvnc/Source/RFBConnection.m
===================================================================
--- cotvnc/Source/RFBConnection.m	(revision 798)
+++ cotvnc/Source/RFBConnection.m	(working copy)
@@ -366,8 +366,9 @@
             break; // no data
 
         if(length <= 0) {	// server closed socket
-            NSString *reason = NSLocalizedString( @"ServerClosed", nil );
-            [self terminateConnection:reason];
+			NSLog(@"Server closed connection");
+            //NSString *reason = NSLocalizedString( @"ServerClosed", nil );
+            [self terminateConnection: nil];
             [pool release];
             free(buf);
             return;
