示例#1
0
文件: host.go 项目: deft-code/go-enet
// enet_host_create
func CreateHost(address *net.UDPAddr, peerCount uint, channelLimit uint, incomingBandwidth uint32, outgoingBandwith uint32) (*Host, error) {
	var c_host *C.ENetHost
	if address != nil {
		c_addr := conv_addr(address)
		c_host = C.enet_host_create(&c_addr, C.size_t(peerCount), C.size_t(channelLimit),
			C.enet_uint32(incomingBandwidth), C.enet_uint32(outgoingBandwith))
	} else {
		c_host = C.enet_host_create(nil, C.size_t(peerCount), C.size_t(channelLimit),
			C.enet_uint32(incomingBandwidth), C.enet_uint32(outgoingBandwith))
	}

	if c_host == nil {
		return nil, errors.New("ENet failed to create an ENetHost.")
	}
	C.enet_host_compress(c_host, nil)
	return &Host{c_host, make(map[*C.ENetPeer]*Peer)}, nil
}
示例#2
0
文件: host.go 项目: boj/goenet
func (h *ENetHost) Compress(compressor *ENetCompressor) {
	C.enet_host_compress((*C.ENetHost)(h), (*C.ENetCompressor)(compressor))
}