ArrayList UDP

Estou fazendo um trabalho utilizando Sockets UDP em Java.
O programa lê uma lista de serviços, grava em um ArrayList de serviços e faz a leitura.
Porém não estou conseguindo passar o ArrayList do servidor para o cliente.
Eu precisaria fazer mais ou menos um sendData = serv.getBytes(); porém, não consigo pegar os bytes de uma lista
Segue meu código

UDPServer

package UDP;

import java.io.ByteArrayOutputStream;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.List;

public class UDPServer{
    public static void main(String[] args) throws Exception{
        
        boolean cadastrou = false;
        List<udp.Servico> serv = new ArrayList<udp.Servico>();

        System.out.println("SERVIDOR");
        DatagramSocket serverSocket = new DatagramSocket(6789);

        byte[] receiveData = new byte[1024];
        byte[] sendData = new byte[1024];
        
        while (true){
            DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
            serverSocket.receive(receivePacket);
            
            InetAddress ipAdrees = receivePacket.getAddress();
            int port = receivePacket.getPort();
            
            String sentence = new String(receivePacket.getData());
            String retorno = "";

            if (Integer.parseInt(sentence.trim()) == 1){
                udp.Arquivo a = new udp.Arquivo();
                serv = a.readFile("C:/temp/servicos.txt");

                cadastrou = true;

                retorno = "Serviços cadastrados com sucesso";
            }
            else if (Integer.parseInt(sentence.trim()) == 2){
                retorno = "";
                if (cadastrou){
                    for(int i = 0; i <serv.size(); i++){
                        System.out.println("Enviando serviços");
                        /*AQUI EU PRECISO ENVIAR A LISTA*/
                    }
                    
                    retorno = "Serviços listados";
                }
                else{
                    retorno = "Nenhum serviço cadastrado";
                }
            }

            /*String capitalizedSentence = sentence.toUpperCase();
            sendData = capitalizedSentence.getBytes();*/

            sendData = retorno.getBytes();

            DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, receivePacket.getAddress(), receivePacket.getPort());

            serverSocket.send(sendPacket);
        }
    }
}

UDPClient
package UDP;

import javax.swing.JOptionPane;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
/**
 * @author Bruno Rigo Ghiggi
 * @author Saymon Luan Andres
 */
public class UDPClient {
    public static void main(String[] args) throws Exception {
        System.out.println("CLIENTE");

        BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in));
        DatagramSocket clientSocket = new DatagramSocket();

        InetAddress ipAdress = InetAddress.getByName("127.0.0.1");

        byte[] sendData = new byte[1024];
        byte[] receiveData = new byte[1024];

        int op=0;
        do{
            try{
                String temp = JOptionPane.showInputDialog("Digite \n1 Cadastrar serviços \n2 Visualizar serviços \n0 Sair");
                op = Integer.valueOf(temp);
                switch (op) {
                    case 1:{
                        sendData = Integer.toString(op).getBytes();
                        DatagramPacket sendPacket = null;

                        try{
                            sendPacket = new DatagramPacket(sendData, sendData.length, ipAdress, 6789);
                        }
                        catch (Exception e){
                            System.out.println(e.toString());
                        }
                        clientSocket.send(sendPacket);

                        DatagramPacket receivePacket = null;
                        String modifiedSentence = "";

                        try{
                            receivePacket = new DatagramPacket(receiveData, receiveData.length);
                            clientSocket.receive(receivePacket);

                            modifiedSentence = new String(receivePacket.getData());
                        }
                        catch (Exception e){
                            System.out.println(e.toString());
                        }
                        System.out.println(" FROM SERVER: " + modifiedSentence);
                    }
                    break;
                    case 2:{
                        sendData = Integer.toString(op).getBytes();
                        DatagramPacket sendPacket = null;

                        try{
                            sendPacket = new DatagramPacket(sendData, sendData.length, ipAdress, 6789);
                        }
                        catch (Exception e){
                            System.out.println(e.toString());
                        }
                        clientSocket.send(sendPacket);

                        DatagramPacket receivePacket = null;
                        String modifiedSentence = "";

                        try{
                            receivePacket = new DatagramPacket(receiveData, receiveData.length);
                            clientSocket.receive(receivePacket);

                            modifiedSentence = new String(receivePacket.getData());
                        }
                        catch (Exception e){
                            System.out.println(e.toString());
                        }
                        System.out.println(" FROM SERVER: " + modifiedSentence);
                    }
                    break;
                }
            } catch (Exception ex) {
                JOptionPane.showMessageDialog(null, ex);
                op = -1;
            }
        } while (op != 0);
    }
}

Classe Serviço
package udp;

public class Servico{
    private String servidor, ip, porta, descricao;

    public Servico(String s, String i, String p, String d){
        this.servidor = s;
        this.ip = i;
        this.porta = p;
        this.descricao = d;
    }

    public String getServidor(){
        return servidor;
    }

    public void setServidor(String servidor){
        this.servidor = servidor;
    }

    public String getIp(){
        return ip;
    }

    public void setIp(String ip){
        this.ip = ip;
    }

    public String getPorta(){
        return porta;
    }

    public void setPorta(String porta){
        this.porta = porta;
    }

    public String getDescricao(){
        return descricao;
    }

    public void setDescricao(String descricao){
        this.descricao = descricao;
    }
}

Classe Arquivo
package udp;

import java.util.*;
import java.io.*;

public class Arquivo{
    public List<Servico> readFile(String arq){
        List<Servico> lista = new ArrayList<Servico>();
        String[] temp = new String[4];

        try{
            FileReader fr = new FileReader(arq);
            BufferedReader in = new BufferedReader(fr);
            String line = in.readLine();

            while(line != null){
                for(int i = 0; i < 4; i++){
                    if(line == null)
                        System.err.println("Faltam informaÁıes no arquivo");
                    else{
                        temp[i] = line;
                        temp[i] = temp[i].replace("<", "");
                        temp[i] = temp[i].replace(">", "");
                        line = in.readLine();
                    }
                }

                Servico s = new Servico(temp[0], temp[1], temp[2], temp[3]);
                lista.add(s);
                line = in.readLine();

            }
            in.close();
        }catch (IOException e){
            System.err.printf("Erro na abertura do arquivo: %s.\n",
            e.getMessage());
        }
        return lista;
    }
}
1 curtida