Created
August 17, 2013 23:32
-
-
Save nevyn/6259168 to your computer and use it in GitHub Desktop.
minimal eminet test. Fails.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "EmiNet.h" | |
@interface Foo : NSObject <EmiSocketDelegate, EmiConnectionDelegate> | |
@end | |
@implementation Foo | |
{ | |
EmiSocket *_list; | |
EmiSocket *_conn; | |
} | |
- (void)main | |
{ | |
_list = [[EmiSocket alloc] initWithDelegate:self delegateQueue:dispatch_get_main_queue()]; | |
EmiSocketConfig *listConf = [EmiSocketConfig new]; | |
listConf.acceptConnections = YES; | |
listConf.serverPort = 4243; | |
NSError *err; | |
if(![_list startWithConfig:listConf error:&err]) | |
NSLog(@"Can't listen: %@", err); | |
EmiSocketConfig *connConf = [EmiSocketConfig new]; | |
connConf.initialConnectionTimeout = 5; | |
_conn = [[EmiSocket alloc] initWithDelegate:self delegateQueue:dispatch_get_main_queue()]; | |
if(![_conn startWithConfig:connConf error:&err]) | |
NSLog(@"Can't start conn"); | |
if(![_conn connectToHost:@"localhost" onPort:listConf.serverPort delegate:self delegateQueue:dispatch_get_main_queue() userData:nil error:&err]) | |
NSLog(@"Can't connect"); | |
} | |
- (void)emiSocket:(EmiSocket *)socket gotConnection:(EmiConnection *)connection; | |
{ | |
NSLog(@"Got connection: %@", connection); | |
} | |
- (void)emiConnectionOpened:(EmiConnection *)connection userData:(id)userData | |
{ | |
NSLog(@"Openeed %@", connection); | |
} | |
- (void)emiConnectionFailedToConnect:(EmiSocket *)socket error:(NSError *)error userData:(id)userData | |
{ | |
NSLog(@"Failed to connect %@", error); | |
} | |
- (void)emiConnectionDisconnect:(EmiConnection *)connection forReason:(EmiDisconnectReason)reason | |
{ | |
NSLog(@"Disconnect"); | |
} | |
- (void)emiConnectionMessage:(EmiConnection *)connection | |
channelQualifier:(EmiChannelQualifier)channelQualifier | |
data:(NSData *)data; | |
{ | |
NSLog(@"Data %@", data); | |
} | |
@end | |
// Start with no args to start a client and server, | |
// start with one arg (hostname) to start a client | |
int main (int argc, const char * argv[]) | |
{ | |
if(YES) { | |
@autoreleasepool { | |
Foo *foo = [Foo new]; | |
[foo main]; | |
[[NSRunLoop currentRunLoop] run]; | |
return 0; | |
} | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2013-08-18 01:32:20.810 EmiNetDemo[87142:303] Failed to connect Error Domain=com.emilir.eminet.disconnect Code=3 "The operation couldn’t be completed. (com.emilir.eminet.disconnect error 3.)" | |
2013-08-18 01:32:20.811 EmiNetDemo[87142:303] Disconnect |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment