HTTP & APIs Interview Questions: Realtime & WebSockets

Reviewed by Mark Dickie · Last updated

8 questions on this page you can answer and see marked on the spot. Go to the first one

WebSockets are a communication protocol that provides full-duplex, persistent connections over a single TCP link, designed for realtime data exchange between a client and server. For an interview on HTTP APIs and realtime systems, you should know how a WebSocket handshake upgrades from HTTP, how the protocol differs from HTTP polling and server-sent events, and what trade-offs each approach carries. Expect questions on connection lifecycle, framing, reconnection strategies, and when REST alone is sufficient versus when you need a persistent channel.

HTTP vs. SSE vs. WebSockets

FeatureHTTP Request/ResponseServer-Sent EventsWebSockets
DirectionClient→ServerServer→ClientBidirectional
ConnectionNew per request (or pooled)Persistent, one-wayPersistent, full-duplex
TransportHTTPHTTPTCP (after upgrade)
Reconnect handlingManual (retry logic)Built-inManual
Message framingNone (single response)Text lines, data: fieldsText and binary frames
Typical useCRUD APIs, file downloadsLive feeds, dashboardsChat, multiplayer, live trading

What does a WebSockets interview typically test?

  1. The handshake process: how the client sends an Upgrade header with a Sec-WebSocket-Key, and the server responds with 101 Switching Protocols and a derived Sec-WebSocket-Accept value.
  2. Framing and message types: opcode differentiation between text frames (0x1), binary frames (0x2), ping/pong control frames (0x9/0xA), and close frames (0x8).
  3. Backpressure and flow control: how the receiving side handles slow consumers, partial frames, and large message assembly.
  4. Reconnection and reliability: exponential backoff, heartbeat intervals, and session resumption on dropped connections.
  5. Security concerns: origin validation, authentication token transport (query params vs. first message), and protecting against cross-site WebSocket hijacking.

When should you choose WebSockets over HTTP polling?

Pick WebSockets when you need low-latency, server-initiated messages at high frequency, or when both sides must push data simultaneously. HTTP polling is simpler to deploy behind standard infrastructure and works fine for low update rates or when server push is one-directional. Server-sent events fill the middle ground: one-way server push with automatic reconnection, but no client-to-server channel beyond the initial HTTP request.

Key facts

  • Tarmac's HTTP & APIs interview questions cover 23 questions at difficulty 1–5 of 5.
  • Tarmac tracked 2,644 job postings asking for HTTP & APIs in September 2026.
  • Roles asking for HTTP & APIs advertise a median base salary of US$165,000, across 867 job postings as of September 2026.
  • Tarmac last reviewed these HTTP & APIs interview questions on 13 October 2026.

At a glance

Questions23
Difficulty1–5 of 5
FormatsTrue / false, Short answer, Fill in the blank, Multiple choice, Flashcard, Code output

What you'll review

  1. websockets

Practice questions

Try one before you open the answer. Pick an option and press Check; it's marked on the spot.

True or false: once the initial HTTP handshake completes, a WebSocket connection provides a persistent, full-duplex channel over which both the client and the server can send messages at any time.#

Options

Show answer

True. A WebSocket connection, once the HTTP handshake completes, stays open on a single TCP connection and lets the client and server send messages independently at any time. Plain HTTP/1.1 is request-response: each request gets a reply and the exchange ends, though keep-alive only reuses the connection.

Why:

After the HTTP upgrade handshake, the WebSocket stays open on a single TCP connection, and either side can send messages independently whenever it wants. This is the persistent, full-duplex behaviour the statement describes. Plain HTTP/1.1 differs because it is request-response: the client sends a request, the server replies, and the exchange ends, even though keep-alive may reuse the connection for later requests.

What HTTP status code does a server send to confirm a WebSocket connection upgrade handshake has succeeded?#

Show answer

The server responds with HTTP status code 101 Switching Protocols to confirm the WebSocket upgrade.

Why:

A WebSocket connection begins as an HTTP request with an Upgrade: websocket header. When the server agrees to switch protocols, it responds with HTTP status code 101 (Switching Protocols). After that, the connection transitions from HTTP to the WebSocket protocol on the same TCP socket. Status codes like 200 and 201 are for normal HTTP request success, not protocol upgrades, and 100 is the Continue interim response used for request body expectations.

What is the WebSocket URI scheme used for an unencrypted WebSocket connection (the WebSocket analogue of http://)?#

Show answer

ws://

Why:

RFC 6455 defines two URI schemes for WebSocket endpoints. The ws:// scheme designates an unencrypted WebSocket connection, the direct analogue of http://, while wss:// designates a TLS-secured connection, the analogue of https://. Because the question explicitly asks only about the unencrypted variant, the single correct answer is ws://.

During a WebSocket opening handshake per RFC 6455, a client sends these headers with its GET request: Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ== and Sec-WebSocket-Protocol: chat, mqtt. The server supports mqtt but not chat. Which headers must the server include in its HTTP 101 Switching Protocols response to correctly complete the handshake? Give the header names and, where relevant, their values.#

Show answer

The server's 101 response must include Upgrade: websocket, Connection: Upgrade, Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo= (the base64-encoded SHA-1 of the client key concatenated with the GUID 258EAFA5-E914-47DA-95CA-C5AB0DC85B11), and Sec-WebSocket-Protocol: mqtt, because the server selected mqtt from the subprotocols the client offered.

Why:

Per RFC 6455 Section 4.2.2, a valid 101 response must contain Upgrade: websocket and Connection: Upgrade to switch protocols, and Sec-WebSocket-Accept, which is computed by appending the fixed GUID 258EAFA5-E914-47DA-95CA-C5AB0DC85B11 to the client's Sec-WebSocket-Key, taking the SHA-1 hash, and base64-encoding it; for this key the result is s3pPLMBiTxaQ9kYGzzhZRbK+xOo=. Because the client offered subprotocols and the server supports one of them (mqtt, not chat), the server must echo the selected one in Sec-WebSocket-Protocol: mqtt.

True or False: A WebSocket connection uses a single persistent TCP connection and supports full-duplex (bidirectional) communication, whereas a standard HTTP/1.1 exchange is request-response with the client initiating each cycle.#

Options

Show answer

The statement is true: a WebSocket connection upgrades an initial HTTP request into one persistent TCP connection that supports full-duplex messaging, so either side can send at any time. A standard HTTP/1.1 exchange is request-response, where the client always starts each cycle and the server replies.

Why:

WebSockets begin as an HTTP request carrying an Upgrade header; once the server accepts, the connection switches protocols and stays open as a single persistent TCP channel. Both client and server can send messages at any time without the client first issuing a request. A standard HTTP/1.1 exchange is request-response, where the client initiates each cycle and the server replies, so the statement is true.

When a WebSocket handshake succeeds, what HTTP status code does the server send to indicate that the protocol has been switched? Give the code and its reason phrase.#

Show answer

101 Switching Protocols. The server replies to the client's Upgrade request with this status, and the connection then operates as a WebSocket.

Why:

A WebSocket upgrade request asks the server to switch protocols; on success the server responds with 101 Switching Protocols, after which the connection operates as WebSocket. 426 Upgrade Required is a server demand that the client upgrade, not the success signal.

During the opening handshake of a WebSocket connection, the client sends an HTTP GET request. To request the protocol upgrade, the client sets the Upgrade header to _____ and the Connection header to _____.#

Show answer

During the opening handshake of a WebSocket connection, the client sends an HTTP GET request. To request the protocol upgrade, the client sets the Upgrade header to **websocket** and the Connection header to **Upgrade**.

Why:

The WebSocket opening handshake uses the HTTP Upgrade mechanism. The Upgrade header names the target protocol, which is websocket, and the Connection header carries the Upgrade token so that intermediaries forward the upgrade request rather than treating the header as hop-by-hop and dropping it.

After the opening handshake, what communication mode does WebSocket use over its single persistent TCP connection, and what capability does this give both the client and the server?#

Show answer

Full-duplex (bidirectional) communication. After the handshake, both the client and the server can send messages to each other at any time over a single persistent TCP connection, without either side needing to wait for a request from the other.

Why:

After the WebSocket opening handshake completes, the connection upgrades from HTTP to WebSocket and operates in full-duplex mode over a single persistent TCP connection. Both the client and the server can independently push messages to each other at any time, without either side waiting for the other to make a request first, which is unlike the request-response pattern of plain HTTP. The expected answer names this mode as full-duplex (or equivalently bidirectional) and notes that both sides can send messages at any time over the single persistent connection.

True or false: A WebSocket connection provides a single, persistent, full-duplex communication channel over one TCP connection, so both the client and the server can send messages at any time without waiting for the other side.#

Options

Show answer

True. A WebSocket connection is a persistent, full-duplex channel over one TCP connection, defined in RFC 6455. Either the client or the server can send messages at any time without waiting for a request, unlike HTTP/1.1's request–response pattern.

Why:

The statement is true. RFC 6455 defines WebSocket as a persistent, full-duplex channel carried over a single TCP connection that is established by an HTTP Upgrade handshake. Unlike HTTP/1.1 request–response, where the server can only reply after a request, either endpoint can send frames at any time over that same long-lived connection.

In the WebSocket opening handshake, the client sends an HTTP GET request with the Upgrade and Connection headers. The client must also include the request header _____, which contains a Base64-encoded random value. The server computes a hash of that value with a fixed GUID and returns the result in the _____ response header to prove it understood the handshake.#

Show answer

In the WebSocket opening handshake, the client sends an HTTP GET request with the Upgrade and Connection headers. The client must also include the request header Sec-WebSocket-Key, which contains a Base64-encoded random value. The server computes a hash of that value with a fixed GUID and returns the result in the Sec-WebSocket-Accept response header to prove it understood the handshake.

Why:

RFC 6455 requires the client to send a Sec-WebSocket-Key request header containing a Base64-encoded random 16-byte value. The server concatenates this key with the magic GUID 258EAFA5-E914-47DA-95CA-C5AB0DC85B11, computes SHA-1, Base64-encodes the result, and returns it in the Sec-WebSocket-Accept response header. This round-trip proves the server genuinely processed the WebSocket handshake rather than blindly forwarding an HTTP request.

A team building a real-time chat application is choosing between HTTP long-polling and WebSockets for delivering messages from server to client. Which statement accurately describes a fundamental difference between the two approaches?#

Options

Show answer

WebSockets upgrade an initial HTTP connection into a persistent, full-duplex channel, letting the server push messages without the client re-requesting data. Long-polling instead relies on repeated HTTP request/response cycles, adding per-request overhead and latency. WebSockets run over TCP, not UDP.

Why:

WebSockets begin with an HTTP handshake that upgrades the connection to a persistent, full-duplex channel over TCP, so the server can push messages at any time without the client repeatedly asking for them. Long-polling instead requires the client to issue HTTP requests, or hold one open until data arrives and then re-issue it, which adds per-request overhead and latency. The statement naming UDP is wrong because WebSockets run over TCP. The statement about a new connection per message is backwards, since a WebSocket keeps one connection open rather than opening one per message. The statement that long-polling is full-duplex is wrong, because long-polling is a sequence of request/response exchanges and WebSockets are the full-duplex option.

Describe how a WebSocket connection is established over HTTP. What does the client send to request the upgrade, and what does the server return to confirm the switch to the WebSocket protocol?#

Show answer

The client sends an HTTP/1.1 GET request with Upgrade: websocket and Connection: Upgrade headers, plus a Sec-WebSocket-Key header. If the server supports WebSockets and agrees, it replies with HTTP/1.1 101 Switching Protocols and a Sec-WebSocket-Accept header. After that response, the same TCP connection stops carrying HTTP and carries WebSocket frames for full-duplex messaging.

Why:

The WebSocket handshake (RFC 6455) begins as an ordinary HTTP/1.1 GET request carrying Upgrade: websocket and Connection: Upgrade headers, along with a Sec-WebSocket-Key header. A server that supports WebSockets and accepts the request responds with 101 Switching Protocols and a Sec-WebSocket-Accept value derived from the key. From that point the same TCP connection uses the WebSocket binary framing protocol instead of HTTP semantics, enabling full-duplex message exchange. A strong answer names the request headers, the 101 response, and the fact that the same connection switches protocols.

Explain how a WebSocket connection is established over HTTP, and why it lowers per-message overhead compared with repeated HTTP request/response exchanges.#

Show answer

The client sends an HTTP GET request with Upgrade: websocket and Connection: Upgrade headers (plus a Sec-WebSocket-Key). If the server supports the protocol, it replies with 101 Switching Protocols, and the same TCP connection is then used for WebSocket frames. After the handshake, the connection stays open and both sides can send messages at any time (full-duplex) without a new HTTP request and its headers for each message, which reduces latency and overhead.

Why:

A WebSocket starts as an ordinary HTTP GET carrying Upgrade: websocket headers; a server that accepts it answers 101 Switching Protocols and the same TCP connection is then reused for WebSocket frames. Because that connection persists and supports full-duplex messaging, each message avoids the per-request cost of a new HTTP request/response cycle with its headers, which is why latency and overhead drop for frequent or server-initiated messages.

A server implements a Server-Sent Events (SSE) endpoint to push realtime updates to a browser. What value must the Content-Type response header be set to, and what byte sequence delimits one event from the next in the response stream?#

Show answer

The Content-Type must be text/event-stream. Events are delimited by a blank line, meaning two consecutive newline characters (\n\n), so each event is written as one or more data: lines followed by an empty line. When the client parser reads that empty line, it dispatches the buffered event to the onmessage handler. Per the HTML Living Standard, CRLF and bare CR are also valid line terminators, so a blank line can be any pair of consecutive line terminators.

Why:

The HTML Living Standard requires SSE responses to use the MIME type text/event-stream, which is how the browser's EventSource recognizes the stream. Within the stream, each field is a line, and an event is terminated by an empty line: two consecutive line terminators such as \n\n. When the parser encounters that blank line, it dispatches the buffered event (multiple data: lines in one event are joined with newlines into a single MessageEvent). Both parts of the answer are needed: the MIME type and the blank-line delimiter.

During a WebSocket opening handshake, a client sends an HTTP GET request with Upgrade: websocket and a Sec-WebSocket-Key header. What HTTP status code does a compliant server return to complete the upgrade, and how is the Sec-WebSocket-Accept response header derived from the client's Sec-WebSocket-Key?#

Options

Show answer

A compliant WebSocket server responds with 101 Switching Protocols. The Sec-WebSocket-Accept header is computed by appending the fixed GUID 258EAFA5-E914-47DA-95CA-C5AB0DC85B11 to the client's Sec-WebSocket-Key, taking the SHA-1 hash of the concatenation, and base64-encoding the result. This derivation proves the server understood the upgrade request, distinguishing a true WebSocket endpoint from a plain HTTP intermediary.

Why:

Per RFC 6455, a WebSocket server completes the protocol upgrade by responding with 101 Switching Protocols. To prove it understood the handshake, the server takes the client's Sec-WebSocket-Key value, appends the fixed GUID 258EAFA5-E914-47DA-95CA-C5AB0DC85B11, computes the SHA-1 hash of the concatenation, base64-encodes the result, and returns it in the Sec-WebSocket-Accept header. The status is 101, not 200, because the upgrade is accepted and the protocol is switching. The accept value is derived deterministically from the key plus the GUID — it is neither an echo of the key nor a random nonce. The GUID ensures a non-WebSocket intermediary that ignores the Upgrade header cannot accidentally satisfy the handshake.

A team is building a real-time chat application and is choosing between WebSocket and Server-Sent Events (SSE). What key capability does WebSocket provide that SSE does not, and why is that capability essential for chat? Answer in a few sentences.#

Show answer

WebSocket provides full-duplex, bidirectional communication over a single TCP connection, so the client can send messages to the server and the server can push messages to the client at any time. SSE is unidirectional: only the server can push events to the client over a standard HTTP stream, and the client would need a separate HTTP request (such as a POST) to send anything upstream. For a chat application where the client must send messages in real time without opening a new HTTP request each time, WebSocket's bidirectional capability is the key differentiator.

Why:

SSE is a one-way channel: the server writes events over a persistent HTTP response, and the client cannot send data back over that same stream, so it must use a separate HTTP request. WebSocket upgrades the connection to a full-duplex protocol in which both sides can send frames at any time over the same TCP connection. Chat needs the client to send messages upstream continuously as well as receive them, which makes WebSocket's bidirectional capability the deciding factor.

A client starts a WebSocket connection with an HTTP GET request that includes Upgrade: websocket, Connection: Upgrade, and Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==. The server concatenates the key with the fixed GUID 258EAFA5-E914-47DA-95CA-C5AB0DC85B11, takes the SHA-1 hash, Base64-encodes it, and returns the result as Sec-WebSocket-Accept. What is the primary purpose of this key/accept exchange? Answer in a few sentences.#

Show answer

The key/accept exchange lets the server prove that it actually understood and accepted the WebSocket upgrade request, so the client knows it reached a WebSocket-capable server and not an ordinary HTTP endpoint or proxy that happened to return a 101 or 200. It is a handshake check against cross-protocol abuse, where a non-WebSocket server or intermediary might echo back data that looks like a valid upgrade response. It is not user authentication and it does not encrypt frames; TLS (WSS) handles confidentiality, and the subprotocol is negotiated separately through Sec-WebSocket-Protocol.

Why:

The Sec-WebSocket-Key is a client-generated nonce. The server must append the RFC 6455 magic GUID, hash with SHA-1, and Base64-encode the digest into Sec-WebSocket-Accept. Only a server that parsed the upgrade request and implements the WebSocket protocol can compute this value, so it proves the server understood the handshake and helps prevent cross-protocol attacks in which a plain HTTP server or caching proxy could be tricked into producing something that looks like a WebSocket response. The exchange does not authenticate the user, does not encrypt subsequent frames (that is the job of TLS in WSS), and does not select the subprotocol, which is handled by the separate Sec-WebSocket-Protocol header.

How does a WebSocket connection start, and how does it differ from normal HTTP request/response?#

Show answer

A WebSocket starts as an HTTP/1.1 GET with Upgrade: websocket and Connection: Upgrade headers; the server replies 101 Switching Protocols and the same TCP connection is then upgraded to the WebSocket protocol. Unlike HTTP's one-request-one-response model, the result is a persistent, full-duplex channel where server and client can each send messages at any time without re-establishing a connection.

Why:

The WebSocket handshake (RFC 6455) reuses HTTP only to bootstrap, then leaves the request/response model entirely. The persistent full-duplex channel is what makes WebSockets suited to chat, live dashboards, and multiplayer — use cases where HTTP polling would be wasteful and high-latency.

Per RFC 6455, which WebSocket close status codes are explicitly designated as reserved values that MUST NOT be set as a status code in a Close control frame by an endpoint?#

Options

Show answer

Per RFC 6455, close codes 1005 (no status received), 1006 (abnormal closure), and 1015 (TLS handshake failure) are reserved values that must never appear in a Close frame's status-code field. Code 1004 is reserved for future use but lacks the explicit 'must not be set' restriction. Codes 4000–4999 are for private use, not reserved.

Why:

RFC 6455 §7.4.1 defines three status codes with the explicit restriction 'MUST NOT be set as a status code in a Close control frame by an endpoint': 1005 (No Status Received — used internally when no close code was present), 1006 (Abnormal Closure — used internally when the connection dropped without a close frame), and 1015 (TLS Handshake — used internally when the TLS handshake fails). Although 1004 is listed as 'Reserved,' its entry in the spec merely states it is reserved for future use and does not carry the same 'MUST NOT be set in a Close control frame' language that 1005, 1006, and 1015 carry. The 4000–4999 range is designated for private use (§7.4.2), not reserved, so 4000 is not a forbidden reserved value.

Per RFC 6455 (The WebSocket Protocol), which of the following statements about WebSocket close frames is correct?#

Options

Show answer

Status code 1005 is reserved, and an endpoint must never send it in a close frame. RFC 6455 uses 1005 ('No Status Received') internally to signal that a close frame arrived without a status code. Reserved codes like 1005 and 1006 are therefore never valid in outgoing close frames.

Why:

Per RFC 6455 §7.4.1, status code 1005 ('No Status Received') is a reserved value that an endpoint uses internally when a close frame arrives without a status code; §7.4 forbids sending reserved codes, so no outgoing close frame may carry 1005. The option about 1006 is false for the same reason, since 1006 ('Abnormal Closure') is also reserved and must never appear in a frame on the wire. The option about tearing down TCP immediately is false because §5.5.1 requires an endpoint that receives a close frame to reply with its own close frame before closing the connection. The option about fragmenting close frames is false because §5.5 states that control frames, including close frames (opcode 0x8), MUST NOT be fragmented; only data frames may use continuation frames.

The function below is a minimal WebSocket frame parser following the RFC 6455 binary framing format. The input frame is a complete, single WebSocket frame sent from a client to a server (opcode 0x01 = text). What does this program print when executed?#

def parse_ws_frame(frame: bytes) -> str:0a    b0 = frame[0]0a    fin = (b0 >> 7) & 10a    opcode = b0 & 0x0F0a    b1 = frame[1]0a    masked = (b1 >> 7) & 10a    payload_len = b1 & 0x7F0a    idx = 20a    if payload_len == 126:0a        payload_len = int.from_bytes(frame[idx:idx+2], 'big')0a        idx += 20a    elif payload_len == 127:0a        payload_len = int.from_bytes(frame[idx:idx+8], 'big')0a        idx += 80a    if masked:0a        mask = frame[idx:idx+4]0a        idx += 40a    payload = bytearray(frame[idx:idx+payload_len])0a    if masked:0a        for i in range(len(payload)):0a            payload[i] ^= mask[i % 4]0a    return payload.decode('utf-8')0a0aframe = bytes([0a    0x81, 0x85, 0x37, 0xfa, 0x21, 0x3d,0a    0x7f, 0x9f, 0x4d, 0x51, 0x580a])0aprint(parse_ws_frame(frame))
Show answer
Hello
Why:

The frame bytes begin with 0x81: the high bit (FIN) is 1, and the low nibble (opcode) is 0x01, denoting a final text frame. The second byte 0x85 has the MASK bit set (high bit = 1) and a 7-bit payload length of 5. Per RFC 6455, frames from client to server must be masked; the next four bytes (0x37, 0xfa, 0x21, 0x3d) are the 32-bit masking key. The remaining five bytes (0x7f, 0x9f, 0x4d, 0x51, 0x58) are the masked payload. The parser extracts the masking key, then XORs each payload byte with the corresponding key byte (cyclically: index mod 4): 0x7f^0x37=0x48 ('H'), 0x9f^0xfa=0x65 ('e'), 0x4d^0x21=0x6c ('l'), 0x51^0x3d=0x6c ('l'), 0x58^0x37=0x6f ('o'). The recovered UTF-8 bytes decode to the string 'Hello'.

The Python function below parses raw WebSocket frames per RFC 6455 §5.2. Four frames are fed through it: a fragmented text message sent server-to-client, a client-to-server close frame carrying status code 1000, and a server-to-client pong with empty payload. What does the code print (one line per frame, in order)?#

OPCODES = {0: 'continuation', 1: 'text', 2: 'binary', 8: 'close', 9: 'ping', 10: 'pong'}

def parse_frame(data):
    b0, b1 = data[0], data[1]
    fin = (b0 >> 7) & 1
    opcode = b0 & 0x0F
    masked = (b1 >> 7) & 1
    length = b1 & 0x7F
    idx = 2
    if masked:
        mask_key = data[idx:idx + 4]
        idx += 4
        payload = data[idx:idx + length]
        payload = bytes([payload[i] ^ mask_key[i % 4] for i in range(len(payload))])
    else:
        payload = data[idx:idx + length]
    name = OPCODES.get(opcode, f'opcode{opcode}')
    print(f'{name} fin={fin} masked={masked} len={length}')
    return payload

frames = [
    bytes([0x01, 0x03, 0x48, 0x65, 0x6c]),
    bytes([0x80, 0x02, 0x6c, 0x6f]),
    bytes([0x88, 0x82, 0x12, 0x34, 0x56, 0x78, 0x11, 0xDC]),
    bytes([0x8A, 0x00]),
]

for f in frames:
    parse_frame(f)
Show answer
text fin=0 masked=0 len=3
continuation fin=1 masked=0 len=2
close fin=1 masked=1 len=2
pong fin=1 masked=0 len=0
Why:

Frame 1: byte 0x01 gives FIN=0 and opcode 1 (text); byte 0x03 gives mask bit 0 and length 3, so the line is 'text fin=0 masked=0 len=3'. Frame 2: byte 0x80 gives FIN=1 and opcode 0 (continuation); byte 0x02 gives mask bit 0 and length 2, so the line is 'continuation fin=1 masked=0 len=2'. Frame 3: byte 0x88 gives FIN=1 and opcode 8 (close); byte 0x82 gives mask bit 1 and length 2, so the mask key is read from bytes 2-5 and the two payload bytes are unmasked to 0x03 and 0xE8 (status 1000); the line is 'close fin=1 masked=1 len=2'. Frame 4: byte 0x8A gives FIN=1 and opcode 10 (pong); byte 0x00 gives mask bit 0 and length 0, so the line is 'pong fin=1 masked=0 len=0'. The payload values never get printed, so only the header fields appear in the output.

According to RFC 6455, which statement about WebSocket frame fragmentation and control frames (Close 0x8, Ping 0x9, Pong 0xA) is correct?#

Options

Show answer

Control frames in RFC 6455 (Close, Ping, Pong) must never be fragmented, so their FIN bit is always 1. Section 5.4 explicitly allows them to be sent between the fragments of a data message that is still in progress. Their payloads are capped at 125 bytes, so they cannot be split across continuation frames.

Why:

Section 5.5 of RFC 6455 says control frames MUST NOT be fragmented, so every control frame carries FIN=1, and its payload is limited to 125 bytes, so it can never be split into continuation frames. Section 5.4 explicitly allows control frames to be injected between the fragments of a data message that is still in progress. The fragmentation-of-control-frames option contradicts the no-fragmentation rule, the ban on interleaving contradicts the explicit exception in section 5.4, and the oversized-Ping option contradicts the 125-byte cap, which makes splitting impossible.

Sources

The official documentation these questions are checked against:

Related interview questions

Job market

See http-apis salaries and hiring demand from live job postings.

Practise these until they stick

That's every question we hold on this topic, and the page marks what you pick. What it can't do is remember. A free account keeps every answer, and what you miss comes back until it's right: after a day, then at longer gaps.

Start with this topic

Free · the whole bank · 100 marked answers per 30 days · written feedback on the paid plan

Interview booked? Practise the job ad instead

What moved, monthly

One email a month when the bulletin comes out: what moved in the markets we track, and the new question topics we published. Confirm your address to join. Unsubscribe any time.