send 4bytes message and receive answer
send 4bytes message and receive answer
- Subject: send 4bytes message and receive answer
- From: Carlo Gulliani <email@hidden>
- Date: Wed, 1 Jul 2009 07:55:06 -0700 (PDT)
i need to send 4 bytes message like 0x1001 to server and receive answer from it
i use AsyncSocket and wrote the next code:
...
[socket connectToHost:[arr objectAtIndex:0] onPort:theInteger error:&err];
...
-(void)onSocket:(AsyncSocket *)sock didConnectToHost:(NSString *)host port:(UInt16)port
{
NSLog(@"Connect to %@:%u", host,port);
MTMessageBroker*newBroker = [[[MTMessageBrokeralloc] initWithAsyncSocket:socket] autorelease];
[sock release];
newBroker.delegate = self;
self.messageBroker = newBroker;
[selfsendConfirmationToServer];
}
-(void) sendConfirmationToServer
{
NSString*myString = @"0x1001";
const char *utfMyString = [myString UTF8String];
NSData *sendMe = [NSData dataWithBytes:utfMyString length:4];
MTMessage *newMessage = [[[MTMessage alloc] init] autorelease];
newMessage.tag = 0;
newMessage.dataContent = sendMe;
[self.messageBroker sendMessage:newMessage];
}
#pragma mark MTMessageBroker Delegate Methods
-(void)messageBroker:(MTMessageBroker *)server didReceiveMessage:(MTMessage *)message
{
if ( message.tag == 0 )
{
[selfdisplay:@"Message broker"];
NSString*str = [[[NSStringalloc] initWithData:message.dataContentencoding:NSUTF8StringEncoding] autorelease];
NSLog(@"%@",str);
}
}
- (void)onSocket:(AsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag
{
NSData *strData = [data subdataWithRange:NSMakeRange(0, [data length])];
NSString*msg = [[[NSStringalloc] initWithData:strData encoding:NSUTF8StringEncoding] autorelease];
NSLog(@"%@",msg);
}
but i dont receive answer
Q: how can i send 4 bytes message like 0x1001 and receive answer with help AsyncSocket?
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden