- 浏览: 1444491 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (691)
- linux (207)
- shell (33)
- java (42)
- 其他 (22)
- javascript (33)
- cloud (16)
- python (33)
- c (48)
- sql (12)
- 工具 (6)
- 缓存 (16)
- ubuntu (7)
- perl (3)
- lua (2)
- 超级有用 (2)
- 服务器 (2)
- mac (22)
- nginx (34)
- php (2)
- 内核 (2)
- gdb (13)
- ICTCLAS (2)
- mac android (0)
- unix (1)
- android (1)
- vim (1)
- epoll (1)
- ios (21)
- mysql (3)
- systemtap (1)
- 算法 (2)
- 汇编 (2)
- arm (3)
- 我的数据结构 (8)
- websocket (12)
- hadoop (5)
- thrift (2)
- hbase (1)
- graphviz (1)
- redis (1)
- raspberry (2)
- qemu (31)
- opencv (4)
- socket (1)
- opengl (1)
- ibeacons (1)
- emacs (6)
- openstack (24)
- docker (1)
- webrtc (11)
- angularjs (2)
- neutron (23)
- jslinux (18)
- 网络 (13)
- tap (9)
- tensorflow (8)
- nlu (4)
- asm.js (5)
- sip (3)
- xl2tp (5)
- conda (1)
- emscripten (6)
- ffmpeg (10)
- srt (1)
- wasm (5)
- bert (3)
- kaldi (4)
- 知识图谱 (1)
最新评论
-
wahahachuang8:
我喜欢代码简洁易读,服务稳定的推送服务,前段时间研究了一下go ...
websocket的helloworld -
q114687576:
http://www.blue-zero.com/WebSoc ...
websocket的helloworld -
zhaoyanzimm:
感谢您的分享,给我提供了很大的帮助,在使用过程中发现了一个问题 ...
nginx的helloworld模块的helloworld -
haoningabc:
leebyte 写道太NB了,期待早日用上Killinux!么 ...
qemu+emacs+gdb调试内核 -
leebyte:
太NB了,期待早日用上Killinux!
qemu+emacs+gdb调试内核
只调用ibeacon的接口
加上websocket的接口
websocket的服务端代码,使用tornado
// // ViewController.m // ibb // // Created by xiao7 on 14/12/15. // Copyright (c) 2014年 killinux. All rights reserved. // #import "ViewController.h" @import CoreLocation; @interface ViewController () <CLLocationManagerDelegate> @property NSMutableDictionary *beacons; @property CLLocationManager *locationManager; @property NSMutableDictionary *rangedRegions; @property (nonatomic, copy, readonly) NSArray *supportedProximityUUIDs; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; NSLog(@"viewDidLoad------"); self.beacons = [[NSMutableDictionary alloc] init]; self.locationManager = [[CLLocationManager alloc] init]; self.locationManager.delegate = self; [self.locationManager requestAlwaysAuthorization]; self.rangedRegions = [[NSMutableDictionary alloc] init]; _supportedProximityUUIDs = @[ [[NSUUID alloc] initWithUUIDString:@"E2C56DB5-DFFB-48D2-B060-D0F5A71096E0"], [[NSUUID alloc] initWithUUIDString:@"DDDDDDDD-DDDD-DDDD-AAAA-DDDDDDDDDDDD"] //,[[NSUUID alloc] initWithUUIDString:@"DDDDDDDD-DDDD-DDDD-DDDD-DDDDDDDDDDDD"] ]; for (NSUUID *uuid in _supportedProximityUUIDs) { CLBeaconRegion *region = [[CLBeaconRegion alloc] initWithProximityUUID:uuid identifier:[uuid UUIDString]]; self.rangedRegions[region] = [NSArray array]; } } - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; for (CLBeaconRegion *region in self.rangedRegions) { [self.locationManager startRangingBeaconsInRegion:region]; } } - (void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region { NSLog(@"locationManager--------didRangeBeacons:%d",beacons.count); self.rangedRegions[region] = beacons; [self.beacons removeAllObjects]; NSLog(@"locationManager-begin"); if(beacons.count!=0){ NSArray *allvalue=[self.rangedRegions allValues]; if(allvalue.count==2){ NSArray *regionResult = allvalue[0]; CLBeacon *thisregion = regionResult[0]; //NSLog(@"--%.2f", thisregion.accuracy); NSArray *regionResult2 = allvalue[1]; if(regionResult2.count>0){ CLBeacon *thisregion2 = regionResult2[0]; // NSLog(@"--%.2f", thisregion2.accuracy); if(thisregion.accuracy>0 && thisregion2.accuracy>0){ NSLog(@"%.2f", thisregion2.accuracy-thisregion.accuracy); if((thisregion2.accuracy-thisregion.accuracy)<0){ NSLog(@"left"); }else{ //NSLog(@"%.2f", ABS(thisregion2.accuracy-thisregion.accuracy)); if(ABS(thisregion2.accuracy-thisregion.accuracy)<0.1){ NSLog(@"w"); }else{ NSLog(@"right"); } } } } } } } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
加上websocket的接口
// // ViewController.m // ibb // // Created by xiao7 on 14/12/15. // Copyright (c) 2014年 killinux. All rights reserved. // #import "ViewController.h" #import "SocketRocket/SRWebSocket.h" @import CoreLocation; @interface ViewController () <CLLocationManagerDelegate,SRWebSocketDelegate> @property NSMutableDictionary *beacons; @property CLLocationManager *locationManager; @property NSMutableDictionary *rangedRegions; @property (nonatomic, copy, readonly) NSArray *supportedProximityUUIDs; @property (nonatomic, strong) SRWebSocket *mywebSocket; @end @implementation ViewController //NSString *websocket_url = @"ws://haoning.net/webs/websocket/test"; NSString *websocket_url = @"ws://192.168.0.112:8000/chat"; - (void)viewDidLoad { [super viewDidLoad]; //websocket init _mywebSocket.delegate = nil; [_mywebSocket close]; _mywebSocket = [[SRWebSocket alloc] initWithURLRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:websocket_url]]]; _mywebSocket.delegate = self; [_mywebSocket open]; NSLog(@"viewDidLoad------"); self.beacons = [[NSMutableDictionary alloc] init]; self.locationManager = [[CLLocationManager alloc] init]; self.locationManager.delegate = self; [self.locationManager requestAlwaysAuthorization]; self.rangedRegions = [[NSMutableDictionary alloc] init]; _supportedProximityUUIDs = @[ [[NSUUID alloc] initWithUUIDString:@"E2C56DB5-DFFB-48D2-B060-D0F5A71096E0"], [[NSUUID alloc] initWithUUIDString:@"DDDDDDDD-DDDD-DDDD-AAAA-DDDDDDDDDDDD"] //,[[NSUUID alloc] initWithUUIDString:@"DDDDDDDD-DDDD-DDDD-DDDD-DDDDDDDDDDDD"] ]; for (NSUUID *uuid in _supportedProximityUUIDs) { CLBeaconRegion *region = [[CLBeaconRegion alloc] initWithProximityUUID:uuid identifier:[uuid UUIDString]]; self.rangedRegions[region] = [NSArray array]; } } - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; for (CLBeaconRegion *region in self.rangedRegions) { [self.locationManager startRangingBeaconsInRegion:region]; } } - (void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region { NSLog(@"locationManager--------didRangeBeacons:%d",beacons.count); self.rangedRegions[region] = beacons; [self.beacons removeAllObjects]; NSLog(@"locationManager-begin"); if(beacons.count!=0){ NSArray *allvalue=[self.rangedRegions allValues]; if(allvalue.count==2){ NSArray *regionResult = allvalue[0]; CLBeacon *thisregion = regionResult[0]; //NSLog(@"--%.2f", thisregion.accuracy); NSArray *regionResult2 = allvalue[1]; if(regionResult2.count>0){ CLBeacon *thisregion2 = regionResult2[0]; // NSLog(@"--%.2f", thisregion2.accuracy); if(thisregion.accuracy>0 && thisregion2.accuracy>0){ NSLog(@"%.2f", thisregion2.accuracy-thisregion.accuracy); if((thisregion2.accuracy-thisregion.accuracy)<0){ NSLog(@"left"); [_mywebSocket send:@"a"]; }else{ //NSLog(@"%.2f", ABS(thisregion2.accuracy-thisregion.accuracy)); if(ABS(thisregion2.accuracy-thisregion.accuracy)<0.1){ NSLog(@"w"); [_mywebSocket send:@"w"]; }else{ NSLog(@"right"); [_mywebSocket send:@"d"]; } } } } } } } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } //---------------- //pragma websocket - (void)webSocketDidOpen:(SRWebSocket *)webSocket; { NSLog(@"Websocket Connected"); self.title = @"Connected!"; } - (void)webSocket:(SRWebSocket *)webSocket didFailWithError:(NSError *)error; { NSLog(@":( Websocket Failed With Error %@", error); _mywebSocket = nil; } - (void)webSocket:(SRWebSocket *)webSocket didReceiveMessage:(id)message; { NSLog(@"websocket Received \"%@\"", message); NSArray *messageArray = [message componentsSeparatedByString:@","]; if(messageArray.count<3){ NSLog(@"error parameter not right:%@",message); // NSDictionary *dict8 = [NSDictionary dictionaryWithObjectsAndKeys:@"haoning",@"name",message,@"content", nil]; // [_resultArray addObject:dict8]; }else{ NSDictionary *dict8 = [NSDictionary dictionaryWithObjectsAndKeys:messageArray[0],@"name",messageArray[2],@"content", nil]; } } - (void)webSocket:(SRWebSocket *)webSocket didCloseWithCode:(NSInteger)code reason:(NSString *)reason wasClean:(BOOL)wasClean; { NSLog(@"WebSocket closed"); self.title = @"Connection Closed! (see logs)"; _mywebSocket = nil; } @end
websocket的服务端代码,使用tornado
#!/usr/bin/python #coding:utf-8 import os.path import tornado.httpserver import tornado.web import tornado.ioloop import tornado.options import tornado.httpclient import tornado.websocket import json import RPi.GPIO as GPIO import time #GPIO.setwarnings(False) #GPIO.setmode(GPIO.BCM) #GPIO.setup(17,GPIO.OUT) #GPIO.setup(18,GPIO.OUT) #GPIO.setup(22,GPIO.OUT) #GPIO.setup(23,GPIO.OUT) class IndexHandler(tornado.web.RequestHandler): def get(self): self.render("index.html") class SocketHandler(tornado.websocket.WebSocketHandler): """docstring for SocketHandler""" clients = set() @staticmethod def send_to_all(message): for c in SocketHandler.clients: c.write_message(json.dumps(message)) def open(self): # GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) GPIO.setup(17,GPIO.OUT) GPIO.setup(18,GPIO.OUT) GPIO.setup(22,GPIO.OUT) GPIO.setup(23,GPIO.OUT) self.write_message(json.dumps({ 'type': 'sys', 'message': 'Welcome to WebSocket', })) SocketHandler.send_to_all({ 'type': 'sys', 'message': str(id(self)) + ' has joined', }) SocketHandler.clients.add(self) def on_close(self): SocketHandler.clients.remove(self) SocketHandler.send_to_all({ 'type': 'sys', 'message': str(id(self)) + ' has left', }) def on_message(self, message): if(message == 'w'): GPIO.output(17,False) GPIO.output(18,True) GPIO.output(22,False) GPIO.output(23,True) elif(message == 'a'): GPIO.output(17,False) GPIO.output(18,True) GPIO.output(22,False) GPIO.output(23,False) elif(message == 'd'): GPIO.output(17,False) GPIO.output(18,False) GPIO.output(22,False) GPIO.output(23,True) elif(message == 's'): GPIO.output(17,True) GPIO.output(18,False) GPIO.output(22,True) GPIO.output(23,False) else: GPIO.output(17,False) GPIO.output(18,False) GPIO.output(22,False) GPIO.output(23,False) SocketHandler.send_to_all({ 'type': 'user', 'id': id(self), 'message': message, }) ##MAIN if __name__ == '__main__': app = tornado.web.Application( handlers=[ (r"/", IndexHandler), (r"/chat", SocketHandler) ], debug = True, # template_path = os.path.join(os.path.dirname(__file__), "templates"), # static_path = os.path.join(os.path.dirname(__file__), "static") ) app.listen(8000) tornado.ioloop.IOLoop.instance().start()
发表评论
-
facebook的socketrocket总结
2018-03-19 13:36 1378最近看了开源的网易的demo https://netease. ... -
ios的页面跳转
2014-12-03 17:30 1336一种通过导航,一种直 ... -
打包ipa
2014-11-14 23:10 7361.新建一个文件夹命名为:Payload 2.将buid生成的 ... -
理解iOS7的Multipeer Connectivity框架
2014-11-13 23:39 881例子可跑 http://www.oschina.net/tr ... -
ios指南针
2014-10-25 17:06 1049参考http://blog.sina.com.cn/s/blo ... -
linux下编译objectc
2014-10-23 01:24 860编译静态库给ios使用 http://www.tuicool. ... -
ios加速计和陀螺仪
2014-10-22 23:03 1209ios设备中有的加速计可以测量出加速度和重力。陀螺仪可用于确定 ... -
ios仿微信的demo
2014-10-20 00:31 2299510月19日闲的蛋疼,做了个 仿微信的聊天工具 git地址:h ... -
自制微信的ui
2014-10-19 22:28 877参考http://ios.9tech.cn/news/2013 ... -
ios8的tableView使用
2014-10-18 20:34 835ios8是main.storyboard 不是 ... -
ios的opencv的helloworld
2014-10-12 23:38 940xcode6, 学习的源码在 http://opencv.or ... -
ios opencv的一些资源
2014-10-11 00:08 775opencv for ios build http://ww ... -
ios客户端websocket的helloworld
2014-10-09 02:11 23147ios8,xcode6 https://github.com/ ... -
ios8的定位,蓝牙与ios7的区别
2014-10-06 23:27 3618以前程序的地理定位功能在iOS8 版上不能工作了(也可能其 ... -
ios的helloworld 2
2014-09-09 21:51 1267参考视频: www.imooc.com/learn/149 S ... -
ios的helloworld
2014-09-08 19:51 670参考http://www.macx.cn/thread-210 ... -
生成ipa 这个是自己总结的,ios5.1.1越狱系统,xcode4.3.3可用
2012-07-29 20:44 1948最有用的一段 export CODESIGN_ALLOCA ... -
ios上使用gcc
2012-07-18 23:21 3208安装network-cmds apptitude iphone ... -
m3u8在windows上预览
2012-06-12 14:25 6967<html> <head> ... -
cocoahttpserver
2012-03-21 22:19 1918https://github.com/robin/cocoa- ...
相关推荐
使用WebSocket+SpringBoot搭建简易的多人聊天室 由浅入深,配合博客入门教程文章食用,风味独特。 使用WebSocket+SpringBoot搭建简易的多人聊天室 由浅入深,配合博客入门教程文章食用,风味独特。 使用WebSocket+...
本篇博客介绍微信小程序中webSocket的使用方法,以及如何用局部网络建立webSocket连接,进行客户端与服务器之间的对话: webSocket简介 微信小程序端API调用 服务器端使用nodejs配置 演示websocket webSocket...
自己封装的C++语言使用websocket完整代码. 里面集成了Boost库+jsoncpp+websocketpp库,下载后可以直接使用cmake编译运行,不需要配置编译环境.方便大家使用和调试.
原生nodejs使用websocket代码分享.docx
thinkphp6使用workerman websocket连接
压缩包里有收发功能的websocket源码,和"说明"文件。 "说明"里面已经讲的很清楚,从下载,到运行,按照一步步操作即可,搞不定的话+V:noriko1999
把项目拷贝到webstorm即可运行,前端服务器输入vue-cli-service serve运行,后端服务器输入node ws.js运行
网页使用websocket实现网页的实时信息显示。Tomcat+websocket。
Netty中使用WebSocket实现服务端与客户端的长连接通信发送消息示例代码;Netty中使用WebSocket实现服务端与客户端的长连接通信发送消息示例代码;Netty中使用WebSocket实现服务端与客户端的长连接通信发送消息示例代码
页面实现实时从服务器获取到发送的数据
uni-app中H5、PC端websocket使用
服务端使用tomcat7.0 + jsp 客户端使用html5 使用websocket,实现客户端和服务端的双向通信
unty websocket 客户端 服务端 通信 使用WebSocketSharp框架
c++版本,MFC使用websocket客户端的用例,附带github原生的实例
Android使用WebSocket的jar包
本例使用websocket获取服务端的图片并显示在浏览器上,服务端使用java注解方式实现,在tomcat8中调试通过
功能: 1、登录(使用LoginServlet实现) 2、群聊(使用webSocket实现) 3、退出(使用LogoutServlet实现)
使用websocket连接rabbitmqtt搭建IM聊天
websocket需要用到jar包websocket需要用到jar包websocket需要用到jar包
uniapp封装websocket,使用简单,下载复制进项目即可使用,统一使用json收发消息,区分业务类型。 1、使用方法,在需要使用的页面导入改文件(也可以挂载全局) 2、onLoad方法调用this.socketObj = new WebSocketIO...