Exemplo n.º 1
0
/**
 * server read
 **/
func processRead(s *udpsession.Session) {
	conn := *s.C
	LOG.Println("udp2tcp processRead")
	id := s.GetId()
	for {
		buf := make([]byte, 4096)
		n, err := conn.Read(buf[96:])
		if err != nil {
			LOG.Println("server read ", err)
			releaseSession(id, true)
			break
		}

		s.ProcessNewDataToClientProxy(buf[:96+n])
		for {
			p := s.GetNextSendDataToSend()
			if p == nil {
				break
			}
			// tunnel write
			p.LogPacket()
			ut.WritePacketToClientProxy(p)
		}
	}
}
Exemplo n.º 2
0
/**
 * client tcp read
 **/
func processRead(s *udpsession.Session) {
	//LOG.Println("tcp2udp processRead")
	conn := *s.C
	id := s.GetId()
	for {
		/////////////////////////////////////////////////
		buf := make([]byte, 4096)
		length, err := conn.Read(buf[96:])
		if err != nil {
			LOG.Println("client read error", err)
			releaseSession(id, true)
			break
		}
		/////////////////////////////////////////////////
		s.ProcessNewDataToServerProxy(buf[:length+96])

		for {
			p := s.GetNextSendDataToSend()
			if p == nil {
				break
			}
			p.LogPacket()
			rc := ut.WritePacketToServerProxy(p)
			// 检查数据处理结果
			if rc == -1 {
				LOG.Println("client send err")
				break
			}
		}
	}
	conn.Close()
}