Closed clone1018 closed 2 years ago
Seems owncast had the same issue: https://github.com/owncast/owncast/issues/34
Need to look into if they maintain a fork of the RTMP library we should be using instead!
Here's some quick code to do a basic RTMP handshake (and send an invalid one for testing):
package main
import (
"bufio"
"crypto/rand"
"fmt"
"io"
"net"
)
func main() {
token := make([]byte, 1536)
rand.Read(token)
wrongResponse := make([]byte, 1536)
rand.Read(wrongResponse)
conn, err := net.Dial("tcp", "localhost:1935")
if err != nil {
panic(err)
}
reader := bufio.NewReader(conn)
// Write 0x03 and token
conn.Write([]byte{0x03})
conn.Write(token)
// Check status response
status := make([]byte, 1)
_, err = reader.Read(status)
if err != nil {
panic(err)
}
fmt.Printf("First Res: %#v\n", status)
// Generate handshake
handshake := make([]byte, 1536)
_, err = io.ReadFull(conn, handshake)
if err != nil {
panic(err)
}
conn.Write(handshake)
// Uncomment this if you want the handshake to fail
// conn.Write(wrongResponse)
_, err = reader.Read(status)
if err != nil {
panic(err)
}
fmt.Printf("Second Res: %#v\n", status)
}
That fixed it it seems, there were two issues:
Seems for some reason the handshake does not shake successfully with restream, so connecting does not work.
The primary example of this is restream.io