NSString *host= @"localhost";
UInt16 port= 42001;
NSMutableString *message= [NSMutableString stringWithString:@"sensor-update"];
int i;
for(i= 0; i<255; i++) {
[message appendFormat:@" key%d 値%d", i, i];
}
AsyncSocket *socket = [[AsyncSocket alloc] initWithDelegate:self];
NSError *error = nil;
if (![socket connectToHost:host onPort:port error:&error]) {
NSLog(@"Error connecting to server: %@", error);
return;
}
NSData *data= [message dataUsingEncoding:NSUTF8StringEncoding];
NSMutableData *writeData= [NSMutableData data];
char *c= malloc(4);
unsigned n= [data length];
c[0]= (char)((n>>24) & 0xFF);
c[1]= (char)((n>>16) & 0xFF);
c[2]= (char)((n>>8) & 0xFF);
c[3]= (char)(n & 0xFF);
[writeData appendBytes:c length:4];
[writeData appendData:data];
[socket writeData:writeData withTimeout:-1 tag:0];
free(c);
0 件のコメント:
コメントを投稿