i am facing some problems with connecting xcode client with c sharp server. i am running mac in a virtual machine and getting this output
014-03-19 10:30:12.468 FYPSeconf[761:c07] Tcp Client Initialise
2014-03-19 10:30:12.487 FYPSeconf[761:c07] TCP Client - Can't connect to the host
2014-03-19 10:30:12.487 FYPSeconf[761:c07] Data Sent LOGIN,,,192.168.1.1
2014-03-19 10:30:12.488 FYPSeconf[761:c07] Data Recieved (null)
2014-03-19 10:30:12.679 FYPSeconf[761:c07] TCP Client - Can't connect to the host
following is the code that i am using.
- (void)TcpClientInitialise
{
NSLog(@"Tcp Client Initialise");
CFReadStreamRef readStream;
CFWriteStreamRef writeStream;
CFStreamCreatePairWithSocketToHost(NULL, (CFStringRef)@"localhost", 9050, &readStream, &writeStream);
InputStream = (__bridge NSInputStream *)readStream;
OutputStream = (__bridge NSOutputStream *)writeStream;
[InputStream setDelegate:self];
[OutputStream setDelegate:self];
[InputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[OutputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[InputStream open];
[OutputStream open];
}
and for receiving stream
- (void)stream:(NSStream *)theStream handleEvent:(NSStreamEvent)StreamEvent
{
switch (StreamEvent)
{
case NSStreamEventOpenCompleted:
NSLog(@"TCP Client - Stream opened");
break;
case NSStreamEventHasBytesAvailable:
if (theStream == InputStream)
{
uint8_t buffer[1024];
int len;
while ([InputStream hasBytesAvailable])
{
len = [InputStream read:buffer maxLength:sizeof(buffer)];
if (len > 0)
{
NSString *output = [[NSString alloc] initWithBytes:buffer length:len encoding:NSASCIIStringEncoding];
if (nil != output)
{
NSLog(@"TCP Client - Server sent: %@", output);
}
int ActualOutputBytes = [OutputStream write:[OutputData bytes] maxLength:[OutputData length]];
OutputData = nil;
myRecievedString = output;
}
}
}
break;
case NSStreamEventErrorOccurred:
NSLog(@"TCP Client - Can't connect to the host");
break;
case NSStreamEventEndEncountered:
NSLog(@"TCP Client - End encountered");
[theStream close];
[theStream removeFromRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
break;
case NSStreamEventNone:
NSLog(@"TCP Client - None event");
break;
case NSStreamEventHasSpaceAvailable:
NSLog(@"TCP Client - Has space available event");
if (OutputData != nil)
{
int ActualOutputBytes = [OutputStream write:[OutputData bytes] maxLength:[OutputData length]];
if (ActualOutputBytes >= [OutputData length])
{
OutputData = nil;
}
else
{
[OutputData replaceBytesInRange:NSMakeRange(0, ActualOutputBytes) withBytes:NULL length:0];
}
}
break;
default:
NSLog(@"TCP Client - Unknown event");
}
}
please help
and thanks in advance