func (s *Server) sendAck(block int16, client *Client) { packet := make([]byte, 4) packet[0] = 0 packet[1] = 4 // ACK packet[2] = byte((block >> 8) & 0xFF) packet[3] = byte((block) & 0xFF) udp.WriteTo(packet, client.conn, client.remote) }
func sendError(msg string, client *Client) { if len(msg) > 507 { msg = msg[0:508] } packet := make([]byte, 512) packet[0] = 0 packet[1] = 5 // ERROR packet[2] = 0 packet[3] = 1 copy(packet[4:], []byte(msg)) udp.WriteTo(packet[0:5+len(msg)+1], client.conn, client.remote) }
func writeData(data []byte, client *Client) { if len(data) > 512 { data = data[0:512] } packet := make([]byte, 516) // DATA PACKET // 2 bytes opcode // 2 bytes block # // var data block packet[0] = 0 packet[1] = 3 packet[2] = byte((client.block >> 8) & 0xFF) packet[3] = byte((client.block) & 0xFF) if len(data) > 0 { copy(packet[4:], data) } udp.WriteTo(packet[0:4+len(data)], client.conn, client.remote) }