Skip to content

Sockets and files

A browser cannot open TCP connections. Each flash.net.Socket goes instead through a WebSocket relay that you run, for example websockify, which carries binary frames to the server:

configure({
socketProxy: [{ host: "server.example", port: 9000, proxyUrl: "wss://relay.example/9000" }],
// or a function: (host, port) => `wss://relay.example/${host}/${port}`, null to refuse
});

A player you set up yourself takes socket: from webSocketSocketHost(urlFor) (@swf2es/player-hosts/websocket). In node, nodeSocketHost() (@swf2es/player-hosts/node) connects directly, and so does the desktop app, through its main process; both send each write at once, without Nagle’s algorithm, unless an AIR SWF set tcpNoDelay to false before it connected. An embedder with a transport of its own gives it as configure({ sockets }); its connect(host, port, events, options) gets options.noDelay where the SWF set tcpNoDelay.

flash.net.SecureSocket works in node and the desktop app. The desktop asks for the same host-and-port permission as a plain socket, then checks the TLS certificate against the original hostname, including through a proxy. It exposes the peer’s X509Certificate and distinguished names. A SWF can add DER certificates with addBinaryChainBuildingCertificate; they apply only to that Socket. In AIR mode, a self-signed leaf requires the application to accept AIR 51’s cancelable certificateError event explicitly; Flash Player mode refuses it. Expired, wrong-name and broken-chain certificates are refused.

In a browser, SecureSocket goes through a relay of its own that is the TLS client: it connects to the server with TLS, validates the server’s certificate, and carries the plaintext to the page over wss://, in binary frames as a plain socket’s relay does. It is opt-in, apart from socketProxy, in the same forms:

configure({
secureSocketProxy: [{ host: "server.example", port: 443, proxyUrl: "wss://relay.example/tls" }],
});

TLS ends at the relay, so the trust is the relay’s: the SWF sees serverCertificateStatus “trusted” once the relay’s WebSocket opens, and serverCertificate is null. Certificates added with addBinaryChainBuildingCertificate are still checked as DER, but they never reach the relay, which validates against its own trust store. A relay the page reaches over plain ws:// is refused, unless it is on localhost, 127.0.0.1 or [::1], so the plaintext never crosses a network. A relative proxyUrl resolves against the page’s base URL, as the WebSocket would resolve it. A refused or failed relay fails the socket with IOErrorEvent #2031 and status “unknown”.

The relay must validate the server’s certificate and host name. The name it validates is its own configured target, not the host the SWF asked for, so mapping each host and port to the relay for that server is the page’s responsibility. websockify validates from version 0.13.0 with --ssl-target (with Python’s default context: the system’s CAs and the target’s host name); older versions do not. websockify accepts the WebSocket before it connects, so a server it cannot reach or validate shows up as a connect, then a close, not an IOErrorEvent: in between, serverCertificateStatus reads “trusted”, and what the SWF writes on connect goes to the relay, which drops it. No byte from a server it refused reaches the SWF. A relay that connects first and accepts the WebSocket only then fails as Flash does. Without secureSocketProxy, SecureSocket.isSupported is false. A player you set up yourself gives webSocketSecureSocketHost(urlFor) (@swf2es/player-hosts/websocket) as its SocketHost’s secure; any other SocketHost may implement that capability itself.

An AIR application’s air.net.WebSocket uses the page’s own WebSocket. An embedder whose page may not connect, as the desktop app’s, whose main process holds the connections, gives a WebSocketHost of its own as configure({ webSockets }): its connect(url, protocols, events) opens a connection, tells events its open, message, close and error, and returns its send and close.

FileReference and FileReferenceList use the browser’s file chooser. Saving uses the File System Access picker where available, or a Blob download; uploads and downloads use the player’s host fetch. A custom embedder can supply configure({ fileHost }) (FileHost from @swf2es/player), or set fileHost: null to make dialogs cancel. The desktop app supplies native dialogs. Browser dialogs require a recent user click or keypress.