标签:oat begin table udp opengl pre uiimage 屏幕 turn
" dataUsingEncoding:NSUTF8StringEncoding] toHost:@"10.8.155.36" port:5678 withTimeout:-1 tag:100];
}else{
[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(timerClick) userInfo:nil repeats:YES];
}
}
- (void)timerClick{
if (self.ipArray.count == 0) {
return;
}
//设置label的背景颜色
float r = arc4random()%256/255.0;
float g = arc4random()%256/255.0;
float b = arc4random()%256/255.0;
numberLabel.backgroundColor = [UIColor colorWithRed:r green:g blue:b alpha:1];
numberLabel.text = @"抽烟不?跟我一块儿吧";
numberLabel.font = [UIFont boldSystemFontOfSize:40];
//截取屏幕
//第一个參数是截取图片的范围,第二个參数是截取的那一层
UIImage *image = [ZCScreenShot beginImageContext:self.view.frame View:self.view];
//遍历转发
for (NSString *ip in self.ipArray) {
[sendSocket sendData:UIImageJPEGRepresentation(image, 0.1) toHost:ip port:5678 withTimeout:-1 tag:100];
}
}
- (void)createSocket{
//不论是学生端。还是教师端,都须要发送和接受,学生端发送一个签到给教师端,教师端发送图片给学生端
sendSocket = [[AsyncUdpSocket alloc]initWithDelegate:self];
serverSocket = [[AsyncUdpSocket alloc]initWithDelegate:self];
//服务端绑定port
[serverSocket bindToPort:5678 error:nil];
//持续观察
[serverSocket receiveWithTimeout:-1 tag:100];
}
- (void)createView{
if (STU) {
//学生端
imageView = [[UIImageView alloc]initWithFrame:self.view.frame];
[self.view addSubview:imageView];
}else{
//教师端
numberLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 200, 300)];
numberLabel.center = self.view.center;
numberLabel.textAlignment =NSTextAlignmentCenter;
[self.view addSubview:numberLabel];
}
}
#pragma mark -- AsyncUdpSocketDelegate
-(void)onUdpSocket:(AsyncUdpSocket *)sock didSendDataWithTag:(long)tag{
//发送完毕
}
- (BOOL)onUdpSocket:(AsyncUdpSocket *)sock didReceiveData:(NSData *)data withTag:(long)tag fromHost:(NSString *)host port:(UInt16)port{
//接受数据
//教师端接受学生的ip
//学生端接受教师的图片
if (STU) {
if (imageView) {
imageView.image = [UIImage imageWithData:data];
}
imageView.image = [UIImage imageWithData:data];
}else{
//记录学生IP,须要一个数组,对新的数据进行追加,对旧的数据忽略
if (![self.ipArray containsObject:host]) {
[self.ipArray addObject:host];
}
}
//
[sock receiveWithTimeout:-1 tag:100];
return YES;
}
@end
标签:oat begin table udp opengl pre uiimage 屏幕 turn
原文地址:http://www.cnblogs.com/lytwajue/p/6815951.html