Client.java 1.1 KB
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 35 36 37
package universityPB;

import java.io.IOException;
import java.net.Socket;


public class Client {

    public static void main(String[] args) throws IOException {

        Socket s = new Socket("localhost", 9999);


        StudentOuterClass.Student student =
                StudentOuterClass.Student.newBuilder()
                        .setName("John")
                        .setSurname("Cena")
                        .setYob(1977)
                        .setResidence(StudentOuterClass.Student.PlaceOfResidence.newBuilder()
                            .setStreet("Via Celoria")
                            .setNumber(18)
                            .setCity("Milano"))
                        .addExam(StudentOuterClass.Student.Exam.newBuilder()
                                .setName("SDP")
                                .setMark(30)
                                .setDate("31/05/2024"))
                        .build();

        System.out.println("Bytes: " + student.toByteArray().length);
        student.writeTo(s.getOutputStream());

        s.close();


    }
}