SocketRocket Documentation

repository·main·Indexed 27 days ago

https://github.com/facebookincubator/socketrocket

A conforming WebSocket (RFC 6455) client library for iOS, macOS, tvOS, and visionOS. SocketRocket provides an asynchronous, non-blocking interface via the SRWebSocket class and SRWebSocketDelegate protocol, supporting TLS, HTTP proxies, and SSL certificate pinning.

Tokens
567
Snippets
5
Records
7
Agent score
44%

What's inside SocketRocket

  1. Run SocketRocket tests

    main

    SocketRocket includes setup scripts for a Python testing environment using virtualenv.

    To run the short test suite:

    make test

    To run the full test suite (including all tests):

    make test_all

    Alternatively, you can run tests inside Xcode by selecting the SocketRocketTests target and running the test action (⌘+U) on a Mac or Simulator.

  2. Set up the TestChat Demo Server

    main

    The TestChat demo application requires a running server. You can use the provided Python implementation which uses Tornado.

    1. First, ensure the testing environment is set up by running make test in the root directory.
    2. Activate the virtual environment and install the Tornado dependency:
    source .env/bin/activate
    pip install git+https://github.com/tornadoweb/tornado.git
    1. Start the chatroom server:
    python TestChatServer/py/chatroom.py

    Alternatively, you can use the Go implementation:

    cd TestChatServer/go
    go run chatroom.go
    source .env/bin/activate
    pip install git+https://github.com/tornadoweb/tornado.git
    python TestChatServer/py/chatroom.py
  3. Use SRWebSocket to manage WebSocket connections

    main

    The SRWebSocket class is the primary interface for WebSocket communication. It conforms to RFC 6455 and supports TLS (wss), HTTP Proxies, and IPv4/IPv6.

    Important Note on Memory Management: SRWebSocket will retain itself between the call to -(void)open and when it closes, errors, or fails. However, unlike NSURLConnection, SRWebSocket will not retain its delegate.