Example #1
0
File: main.go Project: postfix/xudp
// initConn initializes our connection.
func initConn(port int) *xudp.Connection {
	plugin = reliability.New(nil, nil, nil, nil, 30).(*reliability.Plugin)

	conn := xudp.New(1400)
	conn.Register(plugin)
	err := conn.Open(port)

	if err != nil {
		fmt.Fprintf(os.Stderr, "initConn: %v\n", err)
		os.Exit(1)
	}

	fmt.Printf("Listening on port %d...\n", port)
	return conn
}
Example #2
0
// NewOrderedConnection creates a new ordered connection.
func NewOrderedConnection(mtu uint32) *OrderedConnection {
	c := new(OrderedConnection)
	c.Connection = xudp.New(mtu)
	c.recvCache = make(map[uint32]*Data)
	c.sendCache = make(map[uint32]*Data)
	c.Incoming = make(chan *Data)

	c.Register(reliability.New(
		func(seq uint32, addr net.Addr, data []byte) {
			c.sent(seq, addr, data)
		},
		func(seq uint32, addr net.Addr, data []byte) {
			c.recv(seq, addr, data)
		},
		func(seq uint32) { c.acked(seq) },
		func(seq uint32) { c.lost(seq) },
		30,
	))

	return c
}