Skip to content

Instantly share code, notes, and snippets.

@richp10
Created September 24, 2019 07:41
Show Gist options
  • Save richp10/b5afc98353e548533385af55f587da63 to your computer and use it in GitHub Desktop.
Save richp10/b5afc98353e548533385af55f587da63 to your computer and use it in GitHub Desktop.
Minimal not working pion SCTP example..
package main
import (
"fmt"
"net"
"strconv"
"time"
"github.com/pion/logging"
"github.com/pion/sctp"
)
func CheckError(err error) {
if err != nil {
fmt.Println("Error: ", err)
}
}
func main() {
lg := logging.NewDefaultLoggerFactory()
lg.DefaultLogLevel = logging.LogLevelDebug
ServerAddr, err := net.ResolveUDPAddr("udp", "127.0.0.1:10001")
CheckError(err)
LocalAddr, err := net.ResolveUDPAddr("udp", "127.0.0.1:43")
CheckError(err)
println("Dialing..")
ServerConn, err := net.DialUDP("udp", LocalAddr, ServerAddr)
CheckError(err)
defer ServerConn.Close()
conf := sctp.Config{
LoggerFactory: lg,
NetConn: ServerConn,
}
// Next line fails to complete handshake
seetp, err := sctp.Client(conf)
CheckError(err)
// Never gets here..
_, err = seetp.OpenStream(uint16(22), sctp.PayloadTypeWebRTCBinary )
CheckError(err)
i := 0
for {
println("Sending..")
msg := strconv.Itoa(i)
i++
buf := []byte(msg)
_, err := ServerConn.Write(buf)
if err != nil {
fmt.Println(msg, err)
}
time.Sleep(time.Second * 1)
}
}
package main
import (
"fmt"
"net"
"os"
"github.com/pion/logging"
"github.com/pion/sctp"
)
func CheckError(err error) {
if err != nil {
fmt.Println("Error: ", err)
os.Exit(0)
}
}
func main() {
lg := logging.NewDefaultLoggerFactory()
lg.DefaultLogLevel = logging.LogLevelDebug
ServerAddr, err := net.ResolveUDPAddr("udp", ":10001")
CheckError(err)
ServerConn, err := net.ListenUDP("udp", ServerAddr)
CheckError(err)
defer ServerConn.Close()
conf := sctp.Config{
LoggerFactory: lg,
NetConn: ServerConn,
}
// Does not get beyond this line..
seetp, err := sctp.Server(conf)
CheckError(err)
// Never gets this far..
stream, err := seetp.AcceptStream()
CheckError(err)
buf := make([]byte, 1024)
for {
n, err := stream.Read(buf)
fmt.Println("Received ", string(buf[0:n]))
if err != nil {
fmt.Println("Error: ", err)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment