zoukankan      html  css  js  c++  java
  • webSocket通讯

    1、使用facebook第三方SRWebSocket进行websocket通讯。

      pod 'SocketRocket'

    2、通讯地址:

      ws://192.168.1.128:18882/ws

      注意:socket通讯都是用ws开头的

    3、初始化

       _webSocket = [[SRWebSocket alloc] initWithURL:[NSURL URLWithString:urlStr]];

       _webSocket.delegate = self;

      [_webSocket open];

    4、发送消息

      [_webSocket send:message];

    5、实现协议

      - (void)webSocketDidOpen:(SRWebSocket *)webSocket;

      - (void)webSocket:(SRWebSocket *)webSocket didFailWithError:(NSError *)error;

      - (void)webSocket:(SRWebSocket *)webSocket didReceiveMessageWithString:(nonnullNSString *)string;

      - (void)webSocket:(SRWebSocket *)webSocket didCloseWithCode:(NSInteger)code reason:(NSString *)reason wasClean:(BOOL)wasClean;

      - (void)webSocket:(SRWebSocket *)webSocket didReceivePong:(NSData *)pongPayload;

     6、断开自动重新连接

      _webSocket.delegate = nil;

      _webSocket  =nil;

      [_webSocket close];

      [_webSocket open];

      注意:重新连接一定要先断开、并且置空以后,才可以重新初始化,然后连接

  • 相关阅读:
    弹性盒模型
    CSS3属性
    CSS3选择器
    闭包
    angularjs-select2的使用
    angular 分页插件的使用
    webstorm 破解
    数组和字符串之间的转化
    git 拉取分支代码 合分支
    时间戳转化为时间格式 时间格式转为时间戳
  • 原文地址:https://www.cnblogs.com/shizhiliblog/p/8057469.html
Copyright © 2011-2022 走看看