直播聊天室的建立(一)之socket集成

版本记录

版本号 时间
V1.0 2017.06.04

前言

最近在做移动直播项目,直播间的消息发送,礼物和弹幕走的都是消息服务器,这里建立聊天室需要建立socket,在建立scoket服务器之前需要先和后台服务器协商好协议,然后就可以开始了。这个socketIO工具可以在github上下载,现给出下载地址。
1. SOCKETIO——swift代码

详情

我这里采用的是socketIO swift版本的,工程是用oc写的,因此需要桥接才能使用。

一、文件的桥接

1.建立文件

首先需要建立桥接文件。

桥接文件

2.修改文件名字,并在Build Setting中设置相对路径

配置桥接文件

3.socketIO桥接文件内容

// Generated by Apple Swift version 3.0 (swiftlang-800.0.46.2 clang-800.0.38)
#pragma clang diagnostic push

#if defined(__has_include) && __has_include(<swift/objc-prologue.h>)
# include <swift/objc-prologue.h>
#endif

#pragma clang diagnostic ignored "-Wauto-import"
#include <objc/NSObject.h>
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>

#if !defined(SWIFT_TYPEDEFS)
# define SWIFT_TYPEDEFS 1
# if defined(__has_include) && __has_include(<uchar.h>)
#  include <uchar.h>
# elif !defined(__cplusplus) || __cplusplus < 201103L
typedef uint_least16_t char16_t;
typedef uint_least32_t char32_t;
# endif
typedef float swift_float2  __attribute__((__ext_vector_type__(2)));
typedef float swift_float3  __attribute__((__ext_vector_type__(3)));
typedef float swift_float4  __attribute__((__ext_vector_type__(4)));
typedef double swift_double2  __attribute__((__ext_vector_type__(2)));
typedef double swift_double3  __attribute__((__ext_vector_type__(3)));
typedef double swift_double4  __attribute__((__ext_vector_type__(4)));
typedef int swift_int2  __attribute__((__ext_vector_type__(2)));
typedef int swift_int3  __attribute__((__ext_vector_type__(3)));
typedef int swift_int4  __attribute__((__ext_vector_type__(4)));
typedef unsigned int swift_uint2  __attribute__((__ext_vector_type__(2)));
typedef unsigned int swift_uint3  __attribute__((__ext_vector_type__(3)));
typedef unsigned int swift_uint4  __attribute__((__ext_vector_type__(4)));
#endif

#if !defined(SWIFT_PASTE)
# define SWIFT_PASTE_HELPER(x, y) x##y
# define SWIFT_PASTE(x, y) SWIFT_PASTE_HELPER(x, y)
#endif
#if !defined(SWIFT_METATYPE)
# define SWIFT_METATYPE(X) Class
#endif
#if !defined(SWIFT_CLASS_PROPERTY)
# if __has_feature(objc_class_property)
#  define SWIFT_CLASS_PROPERTY(...) __VA_ARGS__
# else
#  define SWIFT_CLASS_PROPERTY(...)
# endif
#endif

#if defined(__has_attribute) && __has_attribute(objc_runtime_name)
# define SWIFT_RUNTIME_NAME(X) __attribute__((objc_runtime_name(X)))
#else
# define SWIFT_RUNTIME_NAME(X)
#endif
#if defined(__has_attribute) && __has_attribute(swift_name)
# define SWIFT_COMPILE_NAME(X) __attribute__((swift_name(X)))
#else
# define SWIFT_COMPILE_NAME(X)
#endif
#if defined(__has_attribute) && __has_attribute(objc_method_family)
# define SWIFT_METHOD_FAMILY(X) __attribute__((objc_method_family(X)))
#else
# define SWIFT_METHOD_FAMILY(X)
#endif
#if !defined(SWIFT_CLASS_EXTRA)
# define SWIFT_CLASS_EXTRA
#endif
#if !defined(SWIFT_PROTOCOL_EXTRA)
# define SWIFT_PROTOCOL_EXTRA
#endif
#if !defined(SWIFT_ENUM_EXTRA)
# define SWIFT_ENUM_EXTRA
#endif
#if !defined(SWIFT_CLASS)
# if defined(__has_attribute) && __has_attribute(objc_subclassing_restricted)
#  define SWIFT_CLASS(SWIFT_NAME) SWIFT_RUNTIME_NAME(SWIFT_NAME) __attribute__((objc_subclassing_restricted)) SWIFT_CLASS_EXTRA
#  define SWIFT_CLASS_NAMED(SWIFT_NAME) __attribute__((objc_subclassing_restricted)) SWIFT_COMPILE_NAME(SWIFT_NAME) SWIFT_CLASS_EXTRA
# else
#  define SWIFT_CLASS(SWIFT_NAME) SWIFT_RUNTIME_NAME(SWIFT_NAME) SWIFT_CLASS_EXTRA
#  define SWIFT_CLASS_NAMED(SWIFT_NAME) SWIFT_COMPILE_NAME(SWIFT_NAME) SWIFT_CLASS_EXTRA
# endif
#endif

#if !defined(SWIFT_PROTOCOL)
# define SWIFT_PROTOCOL(SWIFT_NAME) SWIFT_RUNTIME_NAME(SWIFT_NAME) SWIFT_PROTOCOL_EXTRA
# define SWIFT_PROTOCOL_NAMED(SWIFT_NAME) SWIFT_COMPILE_NAME(SWIFT_NAME) SWIFT_PROTOCOL_EXTRA
#endif

#if !defined(SWIFT_EXTENSION)
# define SWIFT_EXTENSION(M) SWIFT_PASTE(M##_Swift_, __LINE__)
#endif

#if !defined(OBJC_DESIGNATED_INITIALIZER)
# if defined(__has_attribute) && __has_attribute(objc_designated_initializer)
#  define OBJC_DESIGNATED_INITIALIZER __attribute__((objc_designated_initializer))
# else
#  define OBJC_DESIGNATED_INITIALIZER
# endif
#endif
#if !defined(SWIFT_ENUM)
# define SWIFT_ENUM(_type, _name) enum _name : _type _name; enum SWIFT_ENUM_EXTRA _name : _type
# if defined(__has_feature) && __has_feature(generalized_swift_name)
#  define SWIFT_ENUM_NAMED(_type, _name, SWIFT_NAME) enum _name : _type _name SWIFT_COMPILE_NAME(SWIFT_NAME); enum SWIFT_COMPILE_NAME(SWIFT_NAME) SWIFT_ENUM_EXTRA _name : _type
# else
#  define SWIFT_ENUM_NAMED(_type, _name, SWIFT_NAME) SWIFT_ENUM(_type, _name)
# endif
#endif
#if !defined(SWIFT_UNAVAILABLE)
# define SWIFT_UNAVAILABLE __attribute__((unavailable))
#endif
#if defined(__has_feature) && __has_feature(modules)
@import Foundation;
@import ObjectiveC;
@import Security;
#endif

#pragma clang diagnostic ignored "-Wproperty-attribute-mismatch"
#pragma clang diagnostic ignored "-Wduplicate-method-arg"

@interface NSArray (SWIFT_EXTENSION(iphoneLive))
@end


@interface NSData (SWIFT_EXTENSION(iphoneLive))
@end


@interface NSDictionary (SWIFT_EXTENSION(iphoneLive))
@end


@interface NSDictionary (SWIFT_EXTENSION(iphoneLive))
@end


@interface NSNull (SWIFT_EXTENSION(iphoneLive))
@end


@interface NSString (SWIFT_EXTENSION(iphoneLive))
@end


SWIFT_CLASS("_TtC10iphoneLive7SSLCert")
@interface SSLCert : NSObject
/**
 Designated init for certificates
 \param data is the binary data of the certificate
 
 
 returns:
 a representation security object to be used with
 */
- (nonnull instancetype)initWithData:(NSData * _Nonnull)data OBJC_DESIGNATED_INITIALIZER;
/**
 Designated init for public keys
 \param key is the public key to be used
 
 
 returns:
 a representation security object to be used with
 */
- (nonnull instancetype)initWithKey:(SecKeyRef _Nonnull)key OBJC_DESIGNATED_INITIALIZER;
- (nonnull instancetype)init SWIFT_UNAVAILABLE;
@end


SWIFT_CLASS("_TtC10iphoneLive11SSLSecurity")
@interface SSLSecurity : NSObject
@property (nonatomic) BOOL validatedDN;
/**
 Use certs from main app bundle
 \param usePublicKeys is to specific if the publicKeys or certificates should be used for SSL pinning validation
 
 
 returns:
 a representation security object to be used with
 */
- (nonnull instancetype)initWithUsePublicKeys:(BOOL)usePublicKeys;
/**
 Designated init
 \param keys is the certificates or public keys to use
 
 \param usePublicKeys is to specific if the publicKeys or certificates should be used for SSL pinning validation
 
 
 returns:
 a representation security object to be used with
 */
- (nonnull instancetype)initWithCerts:(NSArray<SSLCert *> * _Nonnull)certs usePublicKeys:(BOOL)usePublicKeys OBJC_DESIGNATED_INITIALIZER;
/**
 Valid the trust and domain name.
 \param trust is the serverTrust to validate
 
 \param domain is the CN domain to validate
 
 
 returns:
 if the key was successfully validated
 */
- (BOOL)isValid:(SecTrustRef _Nonnull)trust domain:(NSString * _Nullable)domain;
- (nonnull instancetype)init SWIFT_UNAVAILABLE;
@end


SWIFT_CLASS("_TtC10iphoneLive16SocketAckEmitter")
@interface SocketAckEmitter : NSObject
- (void)with:(NSArray * _Nonnull)items;
- (nonnull instancetype)init SWIFT_UNAVAILABLE;
@end


SWIFT_CLASS("_TtC10iphoneLive14SocketAnyEvent")
@interface SocketAnyEvent : NSObject
@property (nonatomic, readonly, copy) NSString * _Nonnull event;
@property (nonatomic, readonly, copy) NSArray * _Nullable items;
@property (nonatomic, readonly, copy) NSString * _Nonnull description;
- (nonnull instancetype)init SWIFT_UNAVAILABLE;
@end

@class SocketIOClient;

/**
 Experimental socket manager.
 API subject to change.
 Can be used to persist sockets across ViewControllers.
 Sockets are strongly stored, so be sure to remove them once they are no
 longer needed.
 Example usage:
 \code
 let manager = SocketClientManager.sharedManager
 manager["room1"] = socket1
 manager["room2"] = socket2
 manager.removeSocket(socket: socket2)
 manager["room1"]?.emit("hello")
 
 \endcode*/
SWIFT_CLASS("_TtC10iphoneLive19SocketClientManager")
@interface SocketClientManager : NSObject
SWIFT_CLASS_PROPERTY(@property (nonatomic, class, readonly, strong) SocketClientManager * _Nonnull sharedManager;)
+ (SocketClientManager * _Nonnull)sharedManager;
- (SocketIOClient * _Nullable)objectForKeyedSubscript:(NSString * _Nonnull)string;
- (void)setObject:(SocketIOClient * _Nullable)socket forKeyedSubscript:(NSString * _Nonnull)string;
- (void)addSocket:(SocketIOClient * _Nonnull)socket labeledAs:(NSString * _Nonnull)label;
- (SocketIOClient * _Nullable)removeSocketWithLabel:(NSString * _Nonnull)label;
- (SocketIOClient * _Nullable)removeSocket:(SocketIOClient * _Nonnull)socket;
- (void)removeSockets;
- (nonnull instancetype)init OBJC_DESIGNATED_INITIALIZER;
@end

@protocol SocketEngineClient;
@class NSHTTPCookie;
@class OS_dispatch_queue;
@class WebSocket;
enum SocketEnginePacketType : NSInteger;

SWIFT_PROTOCOL("_TtP10iphoneLive16SocketEngineSpec_")
@protocol SocketEngineSpec
@property (nonatomic, weak) id <SocketEngineClient> _Nullable client;
@property (nonatomic, readonly) BOOL closed;
@property (nonatomic, readonly) BOOL connected;
@property (nonatomic, copy) NSDictionary<NSString *, id> * _Nullable connectParams;
@property (nonatomic, readonly) BOOL doubleEncodeUTF8;
@property (nonatomic, readonly, copy) NSArray<NSHTTPCookie *> * _Nullable cookies;
@property (nonatomic, readonly, copy) NSDictionary<NSString *, NSString *> * _Nullable extraHeaders;
@property (nonatomic, readonly) BOOL fastUpgrade;
@property (nonatomic, readonly) BOOL forcePolling;
@property (nonatomic, readonly) BOOL forceWebsockets;
@property (nonatomic, readonly, strong) OS_dispatch_queue * _Nonnull parseQueue;
@property (nonatomic, readonly) BOOL polling;
@property (nonatomic, readonly) BOOL probing;
@property (nonatomic, readonly, strong) OS_dispatch_queue * _Nonnull emitQueue;
@property (nonatomic, readonly, strong) OS_dispatch_queue * _Nonnull handleQueue;
@property (nonatomic, readonly, copy) NSString * _Nonnull sid;
@property (nonatomic, readonly, copy) NSString * _Nonnull socketPath;
@property (nonatomic, readonly, copy) NSURL * _Nonnull urlPolling;
@property (nonatomic, readonly, copy) NSURL * _Nonnull urlWebSocket;
@property (nonatomic, readonly) BOOL websocket;
@property (nonatomic, readonly, strong) WebSocket * _Nullable ws;
- (nonnull instancetype)initWithClient:(id <SocketEngineClient> _Nonnull)client url:(NSURL * _Nonnull)url options:(NSDictionary * _Nullable)options;
- (void)connect;
- (void)didErrorWithReason:(NSString * _Nonnull)reason;
- (void)disconnectWithReason:(NSString * _Nonnull)reason;
- (void)doFastUpgrade;
- (void)flushWaitingForPostToWebSocket;
- (void)parseEngineData:(NSData * _Nonnull)data;
- (void)parseEngineMessage:(NSString * _Nonnull)message fromPolling:(BOOL)fromPolling;
- (void)write:(NSString * _Nonnull)msg withType:(enum SocketEnginePacketType)type withData:(NSArray<NSData *> * _Nonnull)data;
@end

@class NSURLSession;
@class NSError;

SWIFT_CLASS("_TtC10iphoneLive12SocketEngine")
@interface SocketEngine : NSObject <NSURLSessionDelegate, SocketEngineSpec>
@property (nonatomic, readonly, strong) OS_dispatch_queue * _Nonnull emitQueue;
@property (nonatomic, readonly, strong) OS_dispatch_queue * _Nonnull handleQueue;
@property (nonatomic, readonly, strong) OS_dispatch_queue * _Nonnull parseQueue;
@property (nonatomic, copy) NSDictionary<NSString *, id> * _Nullable connectParams;
@property (nonatomic, copy) NSArray<NSString *> * _Nonnull postWait;
@property (nonatomic) BOOL waitingForPoll;
@property (nonatomic) BOOL waitingForPost;
@property (nonatomic, readonly) BOOL closed;
@property (nonatomic, readonly) BOOL connected;
@property (nonatomic, readonly, copy) NSArray<NSHTTPCookie *> * _Nullable cookies;
@property (nonatomic, readonly) BOOL doubleEncodeUTF8;
@property (nonatomic, readonly, copy) NSDictionary<NSString *, NSString *> * _Nullable extraHeaders;
@property (nonatomic, readonly) BOOL fastUpgrade;
@property (nonatomic, readonly) BOOL forcePolling;
@property (nonatomic, readonly) BOOL forceWebsockets;
@property (nonatomic, readonly) BOOL invalidated;
@property (nonatomic, readonly) BOOL polling;
@property (nonatomic, readonly) BOOL probing;
@property (nonatomic, readonly, strong) NSURLSession * _Nullable session;
@property (nonatomic, readonly, copy) NSString * _Nonnull sid;
@property (nonatomic, readonly, copy) NSString * _Nonnull socketPath;
@property (nonatomic, readonly, copy) NSURL * _Nonnull urlPolling;
@property (nonatomic, readonly, copy) NSURL * _Nonnull urlWebSocket;
@property (nonatomic, readonly) BOOL websocket;
@property (nonatomic, readonly, strong) WebSocket * _Nullable ws;
@property (nonatomic, weak) id <SocketEngineClient> _Nullable client;
- (nonnull instancetype)initWithClient:(id <SocketEngineClient> _Nonnull)client url:(NSURL * _Nonnull)url options:(NSDictionary * _Nullable)options;
/**
 Starts the connection to the server
 */
- (void)connect;
- (void)didErrorWithReason:(NSString * _Nonnull)reason;
- (void)disconnectWithReason:(NSString * _Nonnull)reason;
- (void)doFastUpgrade;
- (void)flushWaitingForPostToWebSocket;
- (void)parseEngineData:(NSData * _Nonnull)data;
- (void)parseEngineMessage:(NSString * _Nonnull)message fromPolling:(BOOL)fromPolling;
/**
 Write a message, independent of transport.
 */
- (void)write:(NSString * _Nonnull)msg withType:(enum SocketEnginePacketType)type withData:(NSArray<NSData *> * _Nonnull)data;
- (void)websocketDidConnect:(WebSocket * _Nonnull)socket;
- (void)websocketDidDisconnect:(WebSocket * _Nonnull)socket error:(NSError * _Nullable)error;
- (nonnull instancetype)init SWIFT_UNAVAILABLE;
@end


@interface SocketEngine (SWIFT_EXTENSION(iphoneLive))
- (void)URLSessionWithSession:(NSURLSession * _Nonnull)session didBecomeInvalidWithError:(NSError * _Nullable)error;
@end


SWIFT_PROTOCOL("_TtP10iphoneLive18SocketEngineClient_")
@protocol SocketEngineClient
- (void)engineDidErrorWithReason:(NSString * _Nonnull)reason;
- (void)engineDidCloseWithReason:(NSString * _Nonnull)reason;
- (void)engineDidOpenWithReason:(NSString * _Nonnull)reason;
- (void)parseEngineMessage:(NSString * _Nonnull)msg;
- (void)parseEngineBinaryData:(NSData * _Nonnull)data;
@end

typedef SWIFT_ENUM(NSInteger, SocketEnginePacketType) {
    SocketEnginePacketTypeOpen = 0,
    SocketEnginePacketTypeClose = 1,
    SocketEnginePacketTypePing = 2,
    SocketEnginePacketTypePong = 3,
    SocketEnginePacketTypeMessage = 4,
    SocketEnginePacketTypeUpgrade = 5,
    SocketEnginePacketTypeNoop = 6,
};


enum SocketIOClientStatus : NSInteger;
@class NSURL;

SWIFT_CLASS("_TtC10iphoneLive14SocketIOClient")
@interface SocketIOClient : NSObject <SocketEngineClient>
@property (nonatomic, readonly, copy) NSURL * _Nonnull socketURL;
@property (nonatomic, readonly, strong) id <SocketEngineSpec> _Nullable engine;
@property (nonatomic, readonly) enum SocketIOClientStatus status;
@property (nonatomic) BOOL forceNew;
@property (nonatomic, copy) NSString * _Nonnull nsp;
@property (nonatomic) BOOL reconnects;
@property (nonatomic) NSInteger reconnectWait;
@property (nonatomic, readonly, copy) NSString * _Nullable sid;
/**
 Not so type safe way to create a SocketIOClient, meant for Objective-C compatiblity.
 If using Swift it’s recommended to use \code
 init(socketURL: NSURL, options: Set<SocketIOClientOption>)
 \endcode
 */
- (nonnull instancetype)initWithSocketURL:(NSURL * _Nonnull)socketURL config:(NSDictionary * _Nullable)config;
/**
 Connect to the server.
 */
- (void)connect;
/**
 Connect to the server. If we aren’t connected after timeoutAfter, call withHandler
 0 Never times out
 */
- (void)connectWithTimeoutAfter:(NSInteger)timeoutAfter withHandler:(void (^ _Nullable)(void))handler;
/**
 Disconnects the socket.
 */
- (void)disconnect;
/**
 Same as emit, but meant for Objective-C
 */
- (void)emit:(NSString * _Nonnull)event with:(NSArray * _Nonnull)items;
/**
 Same as emitWithAck, but for Objective-C
 */
- (void (^ _Nonnull)(uint64_t, void (^ _Nonnull)(NSArray * _Nonnull)))emitWithAck:(NSString * _Nonnull)event with:(NSArray * _Nonnull)items;
- (void)engineDidCloseWithReason:(NSString * _Nonnull)reason;
/**
 error
 */
- (void)engineDidErrorWithReason:(NSString * _Nonnull)reason;
- (void)engineDidOpenWithReason:(NSString * _Nonnull)reason;
/**
 Causes an event to be handled. Only use if you know what you’re doing.
 */
- (void)handleEvent:(NSString * _Nonnull)event data:(NSArray * _Nonnull)data isInternalMessage:(BOOL)isInternalMessage withAck:(NSInteger)ack;
/**
 Leaves nsp and goes back to /
 */
- (void)leaveNamespace;
/**
 Joins namespace
 */
- (void)joinNamespace:(NSString * _Nonnull)namespace_;
/**
 Removes handler(s) based on name
 */
- (void)off:(NSString * _Nonnull)event;
/**
 Removes a handler with the specified UUID gotten from an \code
 on
 \endcode or \code
 once
 \endcode
 */
- (void)offWithId:(NSUUID * _Nonnull)id;
/**
 Adds a handler for an event.
 Returns: A unique id for the handler
 */
- (NSUUID * _Nonnull)on:(NSString * _Nonnull)event callback:(void (^ _Nonnull)(NSArray * _Nonnull, SocketAckEmitter * _Nonnull))callback;
/**
 Adds a single-use handler for an event.
 Returns: A unique id for the handler
 */
- (NSUUID * _Nonnull)once:(NSString * _Nonnull)event callback:(void (^ _Nonnull)(NSArray * _Nonnull, SocketAckEmitter * _Nonnull))callback;
/**
 Adds a handler that will be called on every event.
 */
- (void)onAny:(void (^ _Nonnull)(SocketAnyEvent * _Nonnull))handler;
- (void)parseEngineMessage:(NSString * _Nonnull)msg;
- (void)parseEngineBinaryData:(NSData * _Nonnull)data;
/**
 Tries to reconnect to the server.
 */
- (void)reconnect;
/**
 Removes all handlers.
 Can be used after disconnecting to break any potential remaining retain cycles.
 */
- (void)removeAllHandlers;
- (nonnull instancetype)init SWIFT_UNAVAILABLE;
@end

/**
 <em>NotConnected</em>: initial state
 <em>Disconnected</em>: connected before
 */
typedef SWIFT_ENUM(NSInteger, SocketIOClientStatus) {
    SocketIOClientStatusNotConnected = 0,
    SocketIOClientStatusDisconnected = 1,
    SocketIOClientStatusConnecting = 2,
    SocketIOClientStatusConnected = 3,
};

@class NSStream;

SWIFT_CLASS("_TtC10iphoneLive9WebSocket")
@interface WebSocket : NSObject <NSStreamDelegate>
SWIFT_CLASS_PROPERTY(@property (nonatomic, class, readonly, copy) NSString * _Nonnull ErrorDomain;)
+ (NSString * _Nonnull)ErrorDomain;
/**
 Where the callback is executed. It defaults to the main UI thread queue.
 */
@property (nonatomic, strong) OS_dispatch_queue * _Nonnull callbackQueue;
@property (nonatomic, copy) void (^ _Nullable onConnect)(void);
@property (nonatomic, copy) void (^ _Nullable onDisconnect)(NSError * _Nullable);
@property (nonatomic, copy) void (^ _Nullable onText)(NSString * _Nonnull);
@property (nonatomic, copy) void (^ _Nullable onData)(NSData * _Nonnull);
@property (nonatomic, copy) void (^ _Nullable onPong)(void);
@property (nonatomic, copy) NSDictionary<NSString *, NSString *> * _Nonnull headers;
@property (nonatomic) BOOL voipEnabled;
@property (nonatomic) BOOL selfSignedSSL;
@property (nonatomic, strong) SSLSecurity * _Nullable security;
@property (nonatomic, copy) NSString * _Nullable origin;
@property (nonatomic) NSInteger timeout;
@property (nonatomic, readonly) BOOL isConnected;
@property (nonatomic, readonly, strong) NSURL * _Nonnull currentURL;
/**
 Used for setting protocols.
 */
- (nonnull instancetype)initWithUrl:(NSURL * _Nonnull)url protocols:(NSArray<NSString *> * _Nullable)protocols OBJC_DESIGNATED_INITIALIZER;
/**
 Connect to the WebSocket server on a background thread.
 */
- (void)connect;
/**
 Write a string to the websocket. This sends it as a text frame.
 If you supply a non-nil completion block, I will perform it when the write completes.
 \param str The string to write.
 
 \param completion The (optional) completion handler.
 
 */
- (void)writeString:(NSString * _Nonnull)str completion:(void (^ _Nullable)(void))completion;
/**
 Write binary data to the websocket. This sends it as a binary frame.
 If you supply a non-nil completion block, I will perform it when the write completes.
 \param data The data to write.
 
 \param completion The (optional) completion handler.
 
 */
- (void)writeData:(NSData * _Nonnull)data completion:(void (^ _Nullable)(void))completion;
- (void)writePingWithData:(NSData * _Nonnull)data completion:(void (^ _Nullable)(void))completion;
- (void)stream:(NSStream * _Nonnull)aStream handleEvent:(NSStreamEvent)eventCode;
- (nonnull instancetype)init SWIFT_UNAVAILABLE;
@end

#pragma clang diagnostic pop


二、SOCKETIO swift代码

下面我们就看一下socket IO代码文件组织结构。

代码文档组织结构

这里有很多代码就不给大家粘贴出来了,具体可以在github上下载。

后记

  这一篇先讲述桥接方法和对socketIO进行大体的介绍,后面还会具体说明聊天室中socket的使用方法。

阿凡达悬浮山
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 217,406评论 6 503
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,732评论 3 393
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 163,711评论 0 353
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,380评论 1 293
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,432评论 6 392
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,301评论 1 301
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,145评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,008评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,443评论 1 314
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,649评论 3 334
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,795评论 1 347
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,501评论 5 345
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,119评论 3 328
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,731评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,865评论 1 269
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,899评论 2 370
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,724评论 2 354

推荐阅读更多精彩内容