mozilla

Compare Revisions

Writing a WebSocket server in C#

Change Revisions

Revision 352811:

Revision 352811 by lumia on

Revision 352823:

Revision 352823 by lumia on

Title:
Writing WebSocket server
Writing WebSocket server
Slug:
WebSockets/Writing_WebSocket_server
WebSockets/Writing_WebSocket_server
Content:

Revision 352811
Revision 352823
n39TcpListener(System.Net.<a href="http://msdn.microsoft.com/en-us/ln39TcpListener(System.Net.IPAddress localaddr, int port)
>ibrary/system.net.ipaddress.aspx">IPAddress</a> localaddr, int po 
>rt) 
n197    <h2>n197    <h2 id="Decoding_data">
198      Decoding data198      Decoding messages
t201      &nbsp;t201      After a successful handshake client can send messages to th
 >e server, but now these are encoded.
202    </p>
203    <p>
204      If we sends "MDN", we get these bytes:
205    </p>
206    <table>
207      <tbody>
208        <tr>
209          <td>
210            129
211          </td>
212          <td>
213            131
214          </td>
215          <td>
216            61
217          </td>
218          <td>
219            84
220          </td>
221          <td>
222            35
223          </td>
224          <td>
225            6
226          </td>
227          <td>
228            112
229          </td>
230          <td>
231            16
232          </td>
233          <td>
234            109
235          </td>
236        </tr>
237      </tbody>
238    </table>
239    <p>
240      - 129:
241    </p>
242    <table>
243      <thead>
244        <tr>
245          <th scope="col">
246            FIN (Is this the whole message?)
247          </th>
248          <th scope="col">
249            RSV1
250          </th>
251          <th scope="col">
252            RSV2
253          </th>
254          <th scope="col">
255            RSV3
256          </th>
257          <th scope="col">
258            Opcode
259          </th>
260        </tr>
261      </thead>
262      <tbody>
263        <tr>
264          <td>
265            1
266          </td>
267          <td>
268            0
269          </td>
270          <td>
271            0
272          </td>
273          <td>
274            0
275          </td>
276          <td>
277            0x1=0001
278          </td>
279        </tr>
280      </tbody>
281    </table>
282    <p>
283      You can send your message in frames, but now keep things si
 >mple.<br>
284      <span style="line-height: 1.572;">Opcode</span> <em style="
 >line-height: 1.572;">0x1</em> <span style="line-height: 1.572;">m
 >eans this is a text.</span> <a href="http://tools.ietf.org/html/r
 >fc6455#section-5.2" style="line-height: 1.572;" title="http://too
 >ls.ietf.org/html/rfc6455#section-5.2">Full list of Opcodes</a>
285    </p>
286    <p>
287      - 131:
288    </p>
289    <p>
290      If the second byte minus 128 is between 0 and 125, this is 
 >the length of message. If it is 126, the following 2 bytes, if 12
 >7, the following 3 bytes are the length.
291    </p>
292    <div class="note">
293      <p>
294        I can take 128, because the first bit is always 1.
295      </p>
296    </div>
297    <p>
298      - 61, 84, 35 and 6 are the bytes of key to decode. Changes 
 >every time.
299    </p>
300    <p>
301      The remaining bytes are the<span style="line-height: 1.572;
 >">&nbsp;</span><span style="line-height: 1.572;">encoded</span><s
 >pan style="line-height: 1.572;">&nbsp;message.</span>

Back to History