Exemplo n.º 1
0
func (s *Socket) Send(cmd int, data []byte, f Receiver) {
	var head protocol.PackageHead
	head.Command = uint32(cmd)
	head.PkgLen = uint16(protocol.DATA_PACKAGE_HEAD_SIZE + len(data))
	head.SequenceID = s.pkgSeq

	buf := bytes.NewBuffer(make([]byte, head.PkgLen))
	binary.Write(buf, binary.BigEndian, &head)
	binary.Write(buf, binary.BigEndian, data)
	s.sendQueue <- buf.Bytes()
	// 设置接收处理
	s.recvHandle.Set(s.pkgSeq, f)
	// 包序自增
	s.pkgSeq++
}