socket 发送 BYTES 数组
2013-05-13 22:42
99 查看
- (void)btnClicked:(id)sender event:(id)event
{
NSSet *touches =[event allTouches];
UITouch *touch =[touches anyObject];
CGPoint currentTouchPosition = [touch locationInView:self.controllerTableView];
NSIndexPath *indexPath= [self.controllerTableView indexPathForRowAtPoint:currentTouchPosition];
if (indexPath!= nil){
[self tableView: self.controllerTableView accessoryButtonTappedForRowWithIndexPath:indexPath];
NSLog(@"%d button pressed",[indexPath row]);
if ([indexPath row]== 3){
Byte byte[] = {0xaa, 0x55, 0x00, 0x7b, 0x0f, 0x01, 0x08, 0x00,
0x05, 0x13, 0x01, 0x79, 0x56, 0x34, 0x23, 0x01, 0x03, 0x53,
0x00, 0x7d };
NSData *data = [[NSData alloc] initWithBytes:byte length:20];
[_asyncSocket writeData:data withTimeout:-1 tag:0];
[data release];
[_asyncSocket readDataWithTimeout:-1 tag:0];
}
}
_accessoryBtn = (UIButton *)sender;
if (_accessoryBtn.currentBackgroundImage==self.buttonOFF) {
[_accessoryBtn setBackgroundImage:self.buttonON forState:UIControlStateNormal];
[_accessoryImages replaceObjectAtIndex:[indexPath row] withObject:[UIImage imageNamed:@"but_on"]];
}
else{
[_accessoryBtn setBackgroundImage:self.buttonOFF forState:UIControlStateNormal];
[_accessoryImages replaceObjectAtIndex:[indexPath row] withObject:[UIImage imageNamed:@"but_on_over"]];
}
}
{
NSSet *touches =[event allTouches];
UITouch *touch =[touches anyObject];
CGPoint currentTouchPosition = [touch locationInView:self.controllerTableView];
NSIndexPath *indexPath= [self.controllerTableView indexPathForRowAtPoint:currentTouchPosition];
if (indexPath!= nil){
[self tableView: self.controllerTableView accessoryButtonTappedForRowWithIndexPath:indexPath];
NSLog(@"%d button pressed",[indexPath row]);
if ([indexPath row]== 3){
Byte byte[] = {0xaa, 0x55, 0x00, 0x7b, 0x0f, 0x01, 0x08, 0x00,
0x05, 0x13, 0x01, 0x79, 0x56, 0x34, 0x23, 0x01, 0x03, 0x53,
0x00, 0x7d };
NSData *data = [[NSData alloc] initWithBytes:byte length:20];
[_asyncSocket writeData:data withTimeout:-1 tag:0];
[data release];
[_asyncSocket readDataWithTimeout:-1 tag:0];
}
}
_accessoryBtn = (UIButton *)sender;
if (_accessoryBtn.currentBackgroundImage==self.buttonOFF) {
[_accessoryBtn setBackgroundImage:self.buttonON forState:UIControlStateNormal];
[_accessoryImages replaceObjectAtIndex:[indexPath row] withObject:[UIImage imageNamed:@"but_on"]];
}
else{
[_accessoryBtn setBackgroundImage:self.buttonOFF forState:UIControlStateNormal];
[_accessoryImages replaceObjectAtIndex:[indexPath row] withObject:[UIImage imageNamed:@"but_on_over"]];
}
}
相关文章推荐
- TCP socket发送整形数据(数组,结构体)
- Socket发送Bytes信息到接口
- 关于Socket发送byte数组的问题
- Linux下Socket编程中用send发送结构体
- 安卓socket通信小例子,运用缓存区,发送有限个字节
- socket tcp 发送大数据或文件注意事项
- socket通信阻塞模式下,设置发送和接受函数超时
- 用Socket发送电子邮件----转贴
- 一个socket发送调试信息的类
- socket 发送信息和接收信息 多用于银行通信
- HTTP协议分析系列(五)------php+socket编程发送http请求
- Socket编程 (连接,发送消息) (Tcp、Udp) ,这个是同步,跟上一篇差不多
- 11-socket的实践到内核--UDP的socket数据的发送
- php模拟socket一次连接,多次发送数据的实现代码
- AS3.0的Socket通讯发送固定字符串(指定编码)
- node使用socket断开后延迟发送的问题解决
- 【iOS】Socket/TCP 通信 发送 NSString 字符串格式数据
- C#使用Socket发送和接收TCP数据实例
- Socket 发送文件示例 C# 多线程[转]
- Linux下检测网卡与网线连接状态,使用ioctl向socket发送SIOCETHTOOL命令字