Hu: My secret sauce<1.of-many!>is my ability # to be able to break down complex engineering-tasks into the raw unit task, which can be built, independently; under the principle of cond.oriented-eng<WP.MIC-H2S58>, the raw unit often involves hard–coding the output of what can otherwise be generated by conditional | functions and variable-calls<Turing>. In this case, we need to build a basic test, that will simply pass a hard.coded-string, corresponding to the encoded | string generated by our custom encoding function, through the Web.Sockets-portal, to the server–side. In order to do this, we have to have first # established a hand-shake<WP.MIC-H2S66, H2S75>
H3S1: What Web.Sockets-checks as a raw | requirement:
H4S1: Any length requirement:
H3S2: Composing the string: client->server
H4S1: 1000 |
Hu: The first bit, FIn, is set to 1, since this is an individual message<WP.MIC-H2S81,H2.H4S3>. Since I’m not working with any extensions, the RSV.1-3 bits will also be set to 0 <RFC.6455-5,3>
H4S2: 0001 |
Hu: RFC-6455 specifies that # a text frame will be encoded by # the value of 1 in 4 decimal.point-binary, which evaluates to the literal # 0001. This is the “opcode“.
H4S3: 10000001 |
Hu: The first .point, from the left, is the mask.binary-setting, which must be on for client.to-server, and the next 7, the payload length, which will be 1, because what will be encoded # will be the simplest possible data, either an integer<most-likely> or a char. If payload.length1 is not feasible, we will revisit this point.
H4S4: decbin(random_int(0, 4294967295)) |
Hu: The maximum integer that can be represented by a 32.bit-value<Microsoft, a-r>: is our max | value. After the random_int is generated, we will use decbin to convert the int into a binary representation, as random_int generates using base-10 values, by default # Note that not all randomly generated numbers, from this matrix, will have strlen()=32 # in binary, so we will need a while loop to append 0s to the left, until strlen($result)=32. This is the masking | key.
Hu: We will use a single-bit payload, encoding for int=1; I’m not sure, as of 11/2, whether I should set opcode to 1, for text, or 2, for binary data, if I want to encode for an int, but let’s start with opcode=1, for testing.
H4S6: Resulting string:
H3S3: The function that sends the frame from client->server:
H4S1: The JS-option:
WebSocket.send() method enqueues the specified data<H3S2-H4S6>to be transmitted to the server over the WebSocket | connection, increasing the value of |
bufferedAmount<H5S1>by the number of bytes needed to contain the data. If the data can’t be sent (for example, because it needs to be buffered but the buffer is full), the socket is closed automatically. The browser will throw an exception if you call
send() when the connection is in the
CONNECTING state. If you call
send() when the connection is in the
CLOSED states, the browser will silently discard the data<automation!>
H5S1: WebSocket.bufferedAmount<a-r>: The
WebSocket.bufferedAmount read-only | property returns the number of bytes of data that have been queued using calls to
send() but not yet transmitted to the network. This value resets to zero once all queued | data has been sent. This value does not reset to zero when the connection is closed; if you keep calling
send(), this will continue to climb. Value: an unsigned long. Post: Swiping left on this, for now, for now 11/3/22.
H4S2: Using fwrite and stream_socket_client to send the string to Web-Socket:
Indeed, both calls to fwrite, the only ones that the client ever needs to do, pass strings, to the same | target.<WP.MIC-H2S77>
H3S4: Setting the server to listen:
H3S5: The function that receives the frame from client->server:
Cont from<WP.MIC-H2S77,H3S2.H4S4> Fin.v-1
Hu: I just need to var_dump, or an equivalent #, fread for now, and check the output thematically manually, to move forward to the next stage of testing<Turing>; there’s no need to build my own validator; however, if necessary, I need to check # that the server is connected, or not, as a binary<Turing-2>.
Wang, Vanessa, et al. HTML5 WebSocket: Build Real-Time Applications w/ HTML5. Apress.