facebookincubator /SocketRocket

A conforming Objective-C WebSocket client library.

★ 9,597⑂ 2,004👁 326⑃ 286● 403▤ 5
Objective-CNOASSERTIONCreated 2012-01-30
下载:0.7.10.7.1 ↓0.7.12024-08-31
+0
日增长
9,597
stars
2,004
forks
326
watchers
286
prs
403
issues
5
releases

README

SocketRocket

![Platforms][platforms-svg]
[![License][license-svg]][license-link]

[![Podspec][podspec-svg]][podspec-link]
[![Carthage Compatible][carthage-svg]](carthage-link)

[![Build Status][build-status-svg]][build-status-link]

A conforming WebSocket (RFC 6455) client library for iOS, macOS, tvOS and visionOS.

Test results for SocketRocket here.
You can compare to what modern browsers look like here.

SocketRocket currently conforms to all core ~300 of Autobahn's fuzzing tests 
(aside from two UTF-8 ones where it is merely non-strict tests 6.4.2 and 6.4.4).

 Features/Design

- TLS (wss) support, including self-signed certificates.
- Seems to perform quite well.
- Supports HTTP Proxies.
- Supports IPv4/IPv6.
- Supports SSL certificate pinning.
- Sends ping and can process pong events.
- Asynchronous and non-blocking. Most of the work is done on a background thread.
- Supports iOS, macOS, tvOS.

 Installing

There are a few options. Choose one, or just figure it out:

- CocoaPods

 Add the following line to your Podfile:
 ruby
 pod 'SocketRocket'
 
 Run pod install, and you are all set.
  
- Carthage

 Add the following line to your Cartfile:
 
 github "facebook/SocketRocket"
 
 Run carthage update, and you should now have the latest version of SocketRocket in your Carthage folder.

- Using SocketRocket as a sub-project

  You can also include SocketRocket as a subproject inside of your application if you'd prefer, although we do not recommend this, as it will increase your indexing time significantly. To do so, just drag and drop the SocketRocket.xcodeproj file into your workspace.

 API

 SRWebSocket

The Web Socket.

 Note:

SRWebSocket will retain itself between -(void)open and when it closes, errors, or fails.
This is similar to how NSURLConnection behaves (unlike NSURLConnection, SRWebSocket won't retain the delegate).

 Interface

objective-c
@interface SRWebSocket : NSObject

// Make it with this
- (instancetype)initWithURLRequest:(NSURLRequest )request;

// Set this before opening
@property (nonatomic, weak) id  delegate;

// Open with this
- (void)open;

// Close it with this
- (void)close;

// Send a Data
- (void)sendData:(nullable NSData )data error:(NSError )error;

// Send a UTF8 String
- (void)sendString:(NSString )string error:(NSError )error;

@end


 SRWebSocketDelegate

You implement this

objective-c
@protocol SRWebSocketDelegate 

@optional

- (void)webSocketDidOpen:(SRWebSocket )webSocket;

- (void)webSocket:(SRWebSocket )webSocket didReceiveMessageWithString:(NSString )string;
- (void)webSocket:(SRWebSocket )webSocket didReceiveMessageWithData:(NSData )data;

- (void)webSocket:(SRWebSocket )webSocket didFailWithError:(NSError )error;
- (void)webSocket:(SRWebSocket )webSocket didCloseWithCode:(NSInteger)code reason:(nullable NSString )reason wasClean:(BOOL)wasClean;

@end


 Testing

Included are setup scripts for the python testing environment.
It comes packaged with vitualenv so all the dependencies are installed in 

Top issues

Latest release

0.7.1 0.7.1 2024-08-31
What's Changed
 Add visionOS support by @gabrieldonadel in https://github.com/facebookincubator/SocketRocket/pull/669
 Replace usage of deprecated APIs, fix implicit nullability conversion. by @nlutsenko in https://github.com/facebookincubator/SocketRocket/pull/687

Full Changelog: https://github.com/facebookincubator/SocketRocket/compare/0.7.0...0.7.1

Snapshot: 2026-11-16T09:23:14Z · Data license Apache-2.0 · JSON