Ejemplo n.º 1
0
func (sock *TcpSocket) to_write() {
	var pack *packet.Packet
	for ESTABLISHED == sock._socketState {
		pack = <-sock._writerChannel
		if pack == nil {
			log.Error("get pack error")
			continue
		}
		data := pack.Serialize()
		n, err := sock._conn.Write(data)
		if err != nil {
			if io.ErrShortWrite != err {
				log.Error("write err close--", n)
				sock.closeSock()
				break
			}
		}
		log.Info("send data success")
	}
}
Ejemplo n.º 2
0
func (reactor *ComReactor) OnRead(sock *socket.TcpSocket, pack *packet.Packet) {
	data := pack.GetData()
	log.Info("Recv:", data)
	time.Sleep(1)
	sock.Write(data)
}