package rtmp import ( "net" "time" "encoding/binary" ) func DoHandshake(conn net.Conn) (hs_success bool) { C0C1C2 := make([]byte, 1536*2 + 1) S0S1S2 := make([]byte, 1536*2 + 1) S0S1S2[0] = 3 binary.BigEndian.PutUint32(S0S1S2[1:1+4], uint32(time.Now().UnixMilli())) conn.SetDeadline(time.Now().Add(15 * time.Second)) if _, err := conn.Read(C0C1C2); err != nil || C0C1C2[0] != 3 { return } copy(C0C1C2[1:1536], S0S1S2[1+1536:]) binary.BigEndian.PutUint32(S0S1S2[1+1536+4:1+1536+8], uint32(time.Now().UnixMilli())) if _, err := conn.Write(S0S1S2); err != nil { return } if _, err := conn.Read(C0C1C2[1+1536:]); err != nil { return } hs_success = true conn.SetDeadline(time.Time{}) return }