Answer the question
In order to leave comments, you need to log in
How to transfer data of type Object from the server to the client?
I'm making a PC game and recently started making a server for it. Everything was conceived as follows: the client turns on the game on his computer and registers his account, the program sends an object of the String type to the server, the server accepts it and sends the client a ready registered and saved account. But the trouble is, only data of String and int types can be transferred via Socket!
The server sends an object of type Account to the client:
ServerSocket serverSocket = new ServerSocket(port);
Socket socket = serverSocket.accept();
PrintWriter writer = new PrintWriter(socket.getOutputStream());
writer.println(new Account);
writer.close();
Socket socket = new Socket(host, port);
InputStreamReader streamReader = new InputStreamReader(socket.getInputStream());
BufferedReader bufferedReader = new BufferedReader(streamReader);
Account account = (Account) bufferedReader.read(); //Не работает, так как является типом int
bufferedReader.close();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question