ios客户端websocket的helloworld
来源:互联网 发布:linux 查看文件夹数量 编辑:程序博客网 时间:2024/05/17 04:28
ios8,xcode6
https://github.com/square/SocketRocket
https://github.com/killinux/SocketRocket
中的一个文件夹SocketRocket,3包含三个文件
SRWebSocket.h
SRWebSocket.m
SocketRocket-Prefix.pch
copy到工程中
Java代码 收藏代码
//
// ViewController.h
// TestWebs
//
// Created by xiao7 on 14-10-9.
// Copyright (c) 2014年 killinux. All rights reserved.
//
import
import “SocketRocket/SRWebSocket.h”
@interface ViewController : UIViewController
{
SRWebSocket *webSocket;
}
@end
Java代码 收藏代码
//
// ViewController.m
// TestWebs
//
// Created by xiao7 on 14-10-9.
// Copyright (c) 2014年 killinux. All rights reserved.
//
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
点击查看原始大小图片
server的例子参考
http://haoningabc.iteye.com/blog/2124605
以上部分参考
参考http://nonocast.cn/websocket-in-objective-c/
参考http://wenxin2009.iteye.com/blog/1707304
有出入
- ios客户端websocket的helloworld
- ios客户端websocket的helloworld
- ios客户端websocket的helloworld
- ios客户端websocket的简单使用
- websocket客户端的代码
- websocket客户端的实现
- SocketRocket:iOS WebSocket客户端开源框架
- Websocket客户端的实现例子
- WebSocket客户端
- websocket客户端
- webSocket客户端
- ios版本的helloworld
- ios版本的helloworld
- HTML5 WebSocket之HelloWorld
- HTML5 WebSocket 之 HelloWorld
- WebSocket至HelloWorld
- ios websocket的基本使用
- 一个WebSocket客户端的JavaScript例子
- 将博客搬至CSDN
- 128.You need to generate a report that shows all country names, with corresponding customers (if any
- Android 开发绕不过的坑:你的 Bitmap 究竟占多大内存?
- 安卓Service组件使用系列3:使用IntentService下载网络图片
- java反射和泛型的一点儿总结
- ios客户端websocket的helloworld
- 异或运算实现两个数的交换
- android 常用动画
- 过滤器的应用——统计IP访问次数
- OracleDBConsole 启动出错 特定服务错误代码 2
- 【leetcode】【165】Compare Version Numbers
- 使用Eclipse进行远程调试
- RabbitMQ基础概念详细介绍
- iOS应用崩溃日志分析