- (void)setupRendezvousAdvertising
{
- service = [[NSNetService alloc] initWithDomain:@"" type:[NSString stringWithFormat:@"_%@._tcp.",rndType] name:rndName port:htons(port)];
+ NSString *a = [NSString stringWithFormat:@"_%@._tcp.",rndType];
+ service = [[NSNetService alloc] initWithDomain:@"" type:a name:rndName port:htons(port)];
+ NSLog(@"Advertising a service of type %@ name %@",a,rndName);
[service publish];
}
NSConnection *dcon = [[NSConnection alloc] initWithReceivePort:p1 sendPort:p2];
NSArray *par = [NSArray arrayWithObjects:p2,p1,nil];
[dcon setRootObject:self];
+ NSLog(@"detached server thread");
[NSThread detachNewThreadSelector:@selector(socketAcceptLoop:) toTarget:self withObject:par];
}
{
signed int cfd;
cfd = accept(sockfd,NULL,NULL);
+ NSLog(@"Someone connected!");
[(id)dp newClient:cfd];
}
dieflag = 0;
* @discussion ITInetSocket is an Internet socket class supporting IPv6 and Rendezvous.
*/
@interface ITInetSocket : NSObject <ITByteStreamDelegate> {
- @public
- /*!
- * @var sockfd
- * @abstract KLWONZ
- */
+
int sockfd;
int port;
+ int nc;
unsigned short bufs;
volatile int dieflag;
volatile int actionflag;
ITServiceBrowserDelegate *bd = [[ITServiceBrowserDelegate alloc] initWithDelegate:d];
[browse setDelegate:bd];
- [browse searchForServicesOfType:[NSString stringWithFormat:@"._%@._tcp",type] inDomain:nil];
+ [browse searchForServicesOfType:[NSString stringWithFormat:@"_%@._tcp.",type] inDomain:@""];
}
-(id)initWithFD:(int)fd delegate:(id <ITInetSocketDelegate,NSObject>)d
sarr = nil;
bufs = 512;
actionflag = dieflag = 0;
+ nc = 0;
}
+ [self spinoffReadLoop];
return self;
}
sarr = nil;
bufs = 512;
actionflag = dieflag = 0;
+ nc = 1;
}
return self;
}
while (d = [e nextObject])
{
struct sockaddr *s = (struct sockaddr*)[d bytes];
+ bzero(a,sizeof(struct addrinfo));
a->ai_family = s->sa_family;
a->ai_addr = s;
a->ai_next = malloc(sizeof(struct addrinfo));
-(void)realDoConnection
{
- sockfd = socket(ai_cur->ai_addr->sa_family,SOCK_STREAM,IPPROTO_TCP);
+ sockfd = socket(ai_cur->ai_family,SOCK_STREAM,IPPROTO_TCP);
[self spinoffReadLoop];
}
unsigned long readLen = 0;
signed int err;
[readPipe setDelegate:dp];
+ if (nc){
NSLog(@"Connecting");
err = connect(sockfd,ai_cur->ai_addr,ai_cur->ai_addrlen);
if (err == -1)
[(id)dp errorOccured:ITInetCouldNotConnect during:ITInetSocketConnecting onSocket:self];
goto dieaction;
}
+ }
NSLog(@"Sending finishedConnecting");
[(id)dp finishedConnecting:self];
lstart:
{
[aNetServiceBrowser stop];
[aNetServiceBrowser release];
+ [self release];
}
sock = [[ITInetSocket alloc] initWithDelegate:delegate];
+ NSLog(@"Detected a service! name %@ type %@",[aNetService name],[aNetService type]);
[sock connectWithSockaddrArray:[aNetService addresses]];
}
#import <Foundation/Foundation.h>
#import <ITFoundation/ITInetSocket.h>
+#import <ITFoundation/ITInetServerSocket.h>
-@interface ShowcaseController : NSObject <ITInetSocketDelegate> {
-
+@interface ShowcaseController : NSObject <ITInetSocketDelegate,ITInetServerSocketOwner> {
+ ITInetServerSocket *server;
}
@end
#import "ShowcaseController.h"
#import "ITInetSocket.h"
+#import <Foundation/NSString.h>
+#import <SystemConfiguration/SystemConfiguration.h>
-ITInetSocket *sock;
@implementation ShowcaseController
- (void)awakeFromNib
{
- sock = [[ITInetSocket alloc] initWithDelegate:self];
- NSLog(@"rawr?");
- [sock connectToHost:@"irc.freenode.net" onPort:6667];
+ server = [[ITInetServerSocket alloc] initWithDelegate:self];
+ [server setPort:1338];
+ [server setServiceType:@"ittest" useForPort:NO];
+ [server setServiceName:[(NSString*)SCDynamicStoreCopyComputerName(NULL,NULL) autorelease]];
+ [server start];
+ [ITInetSocket startAutoconnectingToService:@"ittest" delegate:self];
}
- (void) finishedConnecting:(ITInetSocket *)sender {
+ [sender disconnect];
+}
+- (void) errorOccured:(ITInetSocketError)err during:(ITInetSocketState)state onSocket:(in ITInetSocket*)sender
+{
}
-- (void) errorOccured:(ITInetSocketError)err during:(ITInetSocketState)state onSocket:(in ITInetSocket*)sender {NSLog(@"wtf");[sender retryConnection];}
- (void) dataReceived:(ITInetSocket *)sender
{
}
-- (void) newDataAdded:(ITByteStream*)sender {
- static int firstTime = YES;
- NSString *ircini = @"USER m0nk3ys . . :Not Telling\r\nNICK ITFTest\r\n", *irc2 = @"JOIN #iThink\r\nPRIVMSG #iThink :w00t\r\nQUIT :!\r\n";
- NSLog(@"Writing something");
- NSData *d = [NSData dataWithBytes:[firstTime?ircini:irc2 cString] length:[firstTime?ircini:irc2 length]];
- [sock->writePipe writeData:d];
- NSLog(@"Reading something");
- firstTime = NO;
+- (void) newDataAdded:(ITByteStream*)sender
+{
+
+}
+
+- (void)newClientJoined:(ITInetSocket*)client
+{
+
}
@end