Muhammad Zayyad
Muhammad Zayyad

Reputation: 19

How to send h2(http/2) connection preface

I'm writing a simple program for testing how http/2 connection work. I read the RFC specification from: https://httpwg.org/specs/rfc7540.html

I was able to successfully connect and use ALPN to negotiate h2. After the server accepts to use h2. I sent

PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n

Which was described in the RFC7540 specification. After this I was supposed to send a SETTINGS frame which I don't really know what to send, I also read about the SETTINGS frame in the RFC7540 but was unable to understand. Could anyone please just send me an example of what to do next. Sorry for my bad English and Thank you in advance.!

Upvotes: 0

Views: 1210

Answers (1)

sbordet
sbordet

Reputation: 18477

Just for the purpose of getting you started, you can send an empty SETTINGS frame.

If you look at the frame format and at the SETTINGS frame definition, you will realize that for an empty SETTINGS frame you have to send these bytes:

0x00 0x00 0x00       # payload length (3 bytes)
0x04 0x00            # type (1 byte) flags (1 byte)
0x00 0x00 0x00 0x00  # stream id (4 bytes)

You can send these bytes right after the client preface bytes

In summary, send the preface bytes:

0x505249202a20485454502f322e300d0a0d0a534d0d0a0d0a

and then the empty SETTINGS frame bytes:

0x000000040000000000

Upvotes: 2

Related Questions