예제 #1
0
// Entrance method for new websocket connections
func clientConnection(clientsock *websocket.Conn) {
	packet := pnet.NewPacket()
	buffer := make([]uint8, pnet.PACKET_MAXSIZE)
	recv, err := clientsock.Read(buffer)
	if err == nil {
		copy(packet.Buffer[0:recv], buffer[0:recv])
		packet.GetHeader()
		parseFirstMessage(clientsock, packet)
	} else {
		if err.Error() != "EOF" {
			log.Warning("GameServer", "clientConnection", "Client connection error: %v", err.Error())
		}
	}
}
예제 #2
0
// Read data from socket stream
func (cw *ConnectionWrapper) ReceivePoller() {
	for {
		packet := pnet.NewPacket()
		var buffer []uint8
		err := websocket.Message.Receive(cw.socket, &buffer)
		if err == nil {
			copy(packet.Buffer[0:len(buffer)], buffer[0:len(buffer)])
			packet.GetHeader()

			cw.processPacket(packet)
		} else {
			println(err.Error())
			break
		}
	}
}