[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[ERROR] Unable to get socket name. Why?
From: |
Ma Xiaoming |
Subject: |
[ERROR] Unable to get socket name. Why? |
Date: |
Wed, 11 Apr 2012 16:50:15 +0800 |
Dear all,
I can compile the following code, but when I want to run the RunServer.exe,
I got this error:
"RunServer[5996] unable to get socket name"
Could you please teach me how to get rid off this error? Thanks in advance.
-----------------------------------------
The Make File, save with name GNUmakefile
-----------------------------------------
include $(GNUSTEP_MAKEFILES)/common.make
TOOL_NAME = RunServer
RunServer_OBJC_FILES = Server.m
include $(GNUSTEP_MAKEFILES)/tool.make
--------------------
TelephoneDirectory.h
--------------------
#ifndef _TELEPHONE_DIRECTORY_H_
#define _TELEPHOHE_DIRECTORY_H_
@protocol TelephoneDirectory
- (char *) teleNumber: (char *)personName;
@end
#endif /* _TELEPHONE_DIRECTORY_H_ */
--------
Client.m
--------
#include <Foundation/Foundation.h>
/* Include the TelephoneDirectory.h protocol header file */
#include "TelephoneDirectory.h"
/*
* Declare the TelephoneDirectory class that
* implements the 'teleNumber' instance method.
*/
@interface TelephoneDirectory : NSObject <TelephoneDirectory>
@end
/*
* Define the TelephoneDirectory class
* and the instance method (teleNumber).
*/
@implementation TelephoneDirectory : NSObject
- (char *) teleNumber: (char*) personName
{
if (strcmp(personName, "Jack") == 0)
return " 0123 456";
else if (strcmp(personName, "Jill") == 0)
return " 0456 789";
else
return " Number not found";
}
@end
/*
* The main() function: Set up the program
* as a 'Distributed Objects Server'.
*/
int main(void)
{
/*
* Remember, create an instance of the
* NSAutoreleasePool class.
*/
CREATE_AUTORELEASE_POOL(pool);
/* Declare and define the teleponeDirectory object */
TelephoneDirectory *teleDirectory = [[TelephoneDirectory alloc] init];
/*
* Create a mew socket port for your connection.
*/
NSSocketPort *port = [NSSocketPort port];
/*
* Create a connection using the socket port.
*/
NSConnection *connXion = [NSConnection connectionWithReceivePort: port
sendPort: port];
/*
* Set the responding server object to be
* the root object for this connection.
*/
[connXion setRootObject: teleDirectory];
/*
* Try to register a name for the NSConnection,
* and report an error if this is not possible.
*/
if ([connXion registerName: @"DirectoryServer"
withNameServer: [NSSocketPortNameServer sharedInstance]] == NO)
{
NSLog(@"Unable to register as 'DirectoryServer'");
NSLog(@"Perhaps another copy of this program is running?");
exit(1);
}
else
NSLog(@"\n** Managed to register connection as 'DirectoryServer'
**\n");
/* Start the current runloop. */
[[NSRunLoop currentRunLoop] run];
RELEASE(pool);
return 0;
}
-------------------------
Best regards,
Xiaoming
- [ERROR] Unable to get socket name. Why?,
Ma Xiaoming <=