ios客户端websocket的简单使用
来源:互联网 发布:typeface.js 下载 编辑:程序博客网 时间:2024/06/06 08:38
下载地址:https://github.com/square/SocketRocket
https://github.com/killinux/SocketRocket
中的一个文件夹SocketRocket,3包含三个文件
SRWebSocket.h
SRWebSocket.m
SocketRocket-Prefix.pch
copy到工程中
引入4个库
https://github.com/killinux/SocketRocket
中的一个文件夹SocketRocket,3包含三个文件
SRWebSocket.h
SRWebSocket.m
SocketRocket-Prefix.pch
copy到工程中
- #import <UIKit/UIKit.h>
- #import "SocketRocket/SRWebSocket.h"
- @interface ViewController : UIViewController<SRWebSocketDelegate>
- {
- SRWebSocket *webSocket;
- }
- @end
- #import "ViewController.h"
- @interface ViewController ()
- @property (weak, nonatomic) IBOutlet UILabel *showTxt;
- @end
- @implementation ViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view, typically from a nib.
- webSocket.delegate = nil;
- [webSocket close];
- webSocket = [[SRWebSocket alloc] initWithURLRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"ws://192.168.0.102:8887"]]];
- webSocket.delegate = self;
- [webSocket open];
- NSLog(@"open success!");
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- - (void)webSocketDidOpen:(SRWebSocket *)webSocket;
- {
- NSLog(@"Websocket Connected");
- self.title = @"Connected!";
- }
- - (void)webSocket:(SRWebSocket *)webSocket didFailWithError:(NSError *)error;
- {
- NSLog(@":( Websocket Failed With Error %@", error);
- webSocket = nil;
- }
- - (void)webSocket:(SRWebSocket *)webSocket didReceiveMessage:(id)message;
- {
- NSLog(@"Received \"%@\"", message);
- self.showTxt.text = message;
- }
- - (void)webSocket:(SRWebSocket *)webSocket didCloseWithCode:(NSInteger)code reason:(NSString *)reason wasClean:(BOOL)wasClean;
- {
- NSLog(@"WebSocket closed");
- self.title = @"Connection Closed! (see logs)";
- webSocket = nil;
- }
- @end
引入4个库
libicucore.dylib,CFNetwork.framework, Security.framework, Foundation.framework
0 0
- ios客户端websocket的简单使用
- iOS使用webSocket的简单实现
- ios客户端websocket的helloworld
- ios客户端websocket的helloworld
- ios客户端websocket的helloworld
- WebSocket的简单使用
- WebSocket WebSocket的简单用法 WebSocket的使用
- ios websocket的基本使用
- iOS- 简单说说iOS移动客户端SQLite3的基本使用
- WebSocket实现Android客户端之间的简单通讯
- WebSocket实现Android客户端之间的简单通讯
- WebSocket实现Android客户端之间的简单通讯
- websocket客户端的代码
- websocket客户端的实现
- 使用Tomcat8实现WebSocket的简单例子
- webSocket开源框架:简单的使用
- 使用WebSocket开发简单的聊天
- android 使用websocket 实现简单的聊天。
- Ubuntu 14.04下安装mongodb及测试
- iOS Core Data 数据迁移 指南
- SP324099: 无法完成操作(VS2015安装)
- 【第六章】 AOP 之 6.9 代理机制 ——跟我学spring3
- DDR3详解(以Micron MT41J128M8 1Gb DDR3 SDRAM为例)
- ios客户端websocket的简单使用
- Uploadify 3.2 参数属性、事件、方法函数详解
- 判断给定的字符串是否是回文数(用栈实现)
- iOS block 使用
- 图像识别中的深度学习
- Java基本类型与byte数组之间相互转换
- 身份证正则法则
- 硬件调试
- 【备份】Java实现忽略SSL认证请求https