Reputation: 1
I am connecting to a server socket using the following code:
- (void)viewDidLoad {
[super viewDidLoad];
asyncSocket = [[AsyncSocket alloc] initWithDelegate:self];
NSError *err = nil;
//[asyncSocket connectToHost:@"192.168.0.200" onPort:8000 error:&err];
if(![asyncSocket connectToHost:@"192.168.0.78" onPort:2055 error:&err])
{
[asyncSocket connectToHost:@"192.168.0.78" onPort:2055 error:&err];
}
}
Then in the didConnectToHost delegate, i am writing few text:
- (void)onSocket:(AsyncSocket *)sock didConnectToHost:(NSString *)host port:(UInt16)port
{
NSLog(@"onSocket:%p didConnectToHost:%@ port:%hu", sock, host, port);
for(int i=0;i<5;i++){
NSString* str= [NSString stringWithFormat: @"Hello Server: %d",i];
NSData* data=[str dataUsingEncoding:NSUTF8StringEncoding];
[sock writeData:data withTimeout:-1 tag:1];
}
}
When I connect to the socket, the connected message is displayed on the server side console. On the server side, the data is being read from the stream with streamReader. We are using TCPListener class on the server side(c# .Net). But when I write data from the client side socket, and try to read the data sent by client, streamReader object on the server is getting empty data. When we quit the client application, the streamReader object in the server side is getting the data which was sent by the client.
We need to read the data at server side immediately after writing from the client side rather than quitting the application.
Can anyone help me to solve this issue?
Upvotes: 0
Views: 646
Reputation: 7041
you just have to finish the String with '\n' i know its too late so hope it helps someone else
Upvotes: 1