Client.java 1014 Bytes
Newer Older
Michele Fiori's avatar
Michele Fiori committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
package students;

import com.google.gson.Gson;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.net.Socket;
import java.util.ArrayList;

public class Client {
    public static void main(String argv[]) throws Exception {
        Socket clientSocket = new Socket("localhost", 6789);

        DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream());

        ArrayList<Exam> passedExams = new ArrayList<Exam>();
        passedExams.add(new Exam("DPS", 30, new Date(31, 5, 2024)));

        Student student = new Student(
                "John",
                "Cena",
                1977,
                new Address("Via Celoria", 18),
                passedExams
        );

        Gson gson = new Gson();
        System.out.println("Bytes: " + gson.toJson(student).getBytes().length);
        outToServer.writeBytes(gson.toJson(student) + '\n');

        clientSocket.close();
    }
}