{"record":{"id":"1871b6529f26beea","repo":"AlexxIT/go2rtc","slug":"rtmp-wrong-handshake","errorCode":null,"errorMessage":"rtmp: wrong handshake","messagePattern":"rtmp: wrong handshake","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/rtmp/server.go","lineNumber":50,"sourceCode":"\tif err := c.writePacketSize(); err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn c, nil\n}\n\nfunc (c *Conn) serverHandshake() error {\n\t// based on https://rtmp.veriskope.com/docs/spec/\n\t_ = c.conn.SetDeadline(time.Now().Add(core.ConnDeadline))\n\n\t// read C0\n\tb := make([]byte, 1)\n\tif _, err := io.ReadFull(c.rd, b); err != nil {\n\t\treturn err\n\t}\n\n\tif b[0] != 3 {\n\t\treturn errors.New(\"rtmp: wrong handshake\")\n\t}\n\n\t// write S0\n\tif _, err := c.conn.Write([]byte{3}); err != nil {\n\t\treturn err\n\t}\n\n\tb = make([]byte, 1536)\n\n\t// write S1\n\ttsS1 := nowMS()\n\tbinary.BigEndian.PutUint32(b, tsS1)\n\tbinary.BigEndian.PutUint32(b[4:], 0)\n\t_, _ = rand.Read(b[8:])\n\tif _, err := c.conn.Write(b); err != nil {\n\t\treturn err\n\t}\n","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/AlexxIT/go2rtc/blob/c245815e75e2a5fd60b4290f12bfc04e55a984d3/pkg/rtmp/server.go#L32-L68","documentation":"RTMP serverHandshake C0 guard: the first byte read from the client is not RTMP version 3, so the peer is not speaking RTMP (or is sending garbage). The handshake is aborted immediately per spec before S0/S1 are written.","triggerScenarios":"Thrown at pkg/rtmp/server.go:50 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Confirm the client is actually connecting with RTMP to this port","Check for HTTP or RTSP clients hitting the RTMP listener","Inspect for TLS bytes — the client may expect rtmps"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"c245815e75e2a5fd60b4290f12bfc04e55a984d3","analyzedAt":"2026-09-07T11:47:02.965Z","contentChangedAt":"2026-09-07T11:47:02.965Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}