objectinputstream

SocketException: Connection reset on server with ObjectInputStream

别来无恙 提交于 2019-12-02 13:10:32
问题 I'm trying to get my head around the ObjectInputStream/ObjectOutputStream , so I create a very simple server-client application where the client sends a HashMap object over the created stream and the server receives that and prints it out. This my server code: import java.io.*; import java.net.*; public class Server { public static void main(String[] args) throws IOException, ClassNotFoundException { ServerSocket server = new ServerSocket(4444); while (true) { Socket socket = server.accept();

Why is ObjectInputStream readObject() throwing EOF exception

天涯浪子 提交于 2019-12-02 09:17:34
问题 I am stuck with this very strange problem. In the client I am passing in objects like try{ oos.writeObject(new GameStartSerializedObject()); oos.flush(); } catch(Exception e){ e.printStackTrace(); } and in the server I am reading the object try{ //Its my turn thrown_message = player_reader.readObject(); } catch(Exception e){ My question is why am i getting EOF exception. My understanding of object input stream is when i call readObject() i should block until i get an object so how does it

SocketException: Connection reset on server with ObjectInputStream

夙愿已清 提交于 2019-12-02 04:14:18
I'm trying to get my head around the ObjectInputStream/ObjectOutputStream , so I create a very simple server-client application where the client sends a HashMap object over the created stream and the server receives that and prints it out. This my server code: import java.io.*; import java.net.*; public class Server { public static void main(String[] args) throws IOException, ClassNotFoundException { ServerSocket server = new ServerSocket(4444); while (true) { Socket socket = server.accept(); ObjectInputStream objIn = new ObjectInputStream(socket.getInputStream()); if (objIn.readObject() !=

Why is ObjectInputStream readObject() throwing EOF exception

。_饼干妹妹 提交于 2019-12-02 03:54:21
I am stuck with this very strange problem. In the client I am passing in objects like try{ oos.writeObject(new GameStartSerializedObject()); oos.flush(); } catch(Exception e){ e.printStackTrace(); } and in the server I am reading the object try{ //Its my turn thrown_message = player_reader.readObject(); } catch(Exception e){ My question is why am i getting EOF exception. My understanding of object input stream is when i call readObject() i should block until i get an object so how does it know if the eof is reached? Please help! This is how I create object streams ois = new ObjectInputStream

java.io.StreamCorruptedException: Wrong format when reading more than 1 object [duplicate]

三世轮回 提交于 2019-12-01 23:08:08
问题 This question already has an answer here : StreamCorruptedException: invalid type code: AC (1 answer) Closed 2 years ago . I am trying to add an object( of OneChatMessage class) into a file on every button click. And then i try to read all the objects from the file and load it into a ArrayList . But i get a StreamCorruptedException at the second iteration of ObjectInputStream.readObject() in the deserialization function. I have verified that the first iteration works fine. I have read many

ObjectInputStream readObject(): ClassNotFoundException

橙三吉。 提交于 2019-12-01 21:06:53
In both client and server classes, I have an exact same inner class called Data. This Data object is being sent from the server using: ObjectOutputStream output= new ObjectOutputStream(socket.getOutputStream()); output.writeObject(d); (where d is a Data object) This object is received on the client side and cast to a Data object: ObjectInputStream input = new ObjectInputStream(socket.getInputStream()); Object receiveObject = input.readObject(); if (receiveObject instanceof Data){ Data receiveData = (Data) receiveObject; // some code here... } I'm getting a java.lang.ClassNotFoundException:

java.io.StreamCorruptedException: Wrong format when reading more than 1 object [duplicate]

末鹿安然 提交于 2019-12-01 21:02:53
This question already has an answer here: StreamCorruptedException: invalid type code: AC 1 answer I am trying to add an object( of OneChatMessage class) into a file on every button click. And then i try to read all the objects from the file and load it into a ArrayList . But i get a StreamCorruptedException at the second iteration of ObjectInputStream.readObject() in the deserialization function. I have verified that the first iteration works fine. I have read many other posts on the same issue : One suggestion( Deserialize multiple Java Objects ) is to write the entire array list to the file

Receive an object over TCP/IP

雨燕双飞 提交于 2019-12-01 19:43:51
I am going to write a program over TCP/IP and I should send objects by client or by server, It is going right when I want to send or receive strings but when I am trying to read an object: private Socket client; public ThreadedClient(Socket client) { this.client = client; } @Override public void run() { try { ObjectInputStream objIn = new ObjectInputStream(client.getInputStream()); while(true){ try { Object fromClient = objIn.readObject(); } catch (ClassNotFoundException e) {e.printStackTrace();} } } catch (IOException e) {e.printStackTrace();} } I receive an exception: java.io

How to avoid OutOfMemory exception while reading large files in Java

徘徊边缘 提交于 2019-12-01 12:58:51
I am working on the application which reads large amounts of data from a file. Basically, I have a huge file (around 1.5 - 2 gigs) containing different objects (~5 to 10 millions of them per file). I need to read all of them and put them to different maps in the app. The problem is that the app runs out of memory while reading the objects at some point. Only when I set it to use -Xmx4096m - it can handle the file. But if the file will be larger, it won't be able to do that anymore. Here's the code snippet: String sampleFileName = "sample.file"; FileInputStream fileInputStream = null;

How to avoid OutOfMemory exception while reading large files in Java

試著忘記壹切 提交于 2019-12-01 10:56:47
问题 I am working on the application which reads large amounts of data from a file. Basically, I have a huge file (around 1.5 - 2 gigs) containing different objects (~5 to 10 millions of them per file). I need to read all of them and put them to different maps in the app. The problem is that the app runs out of memory while reading the objects at some point. Only when I set it to use -Xmx4096m - it can handle the file. But if the file will be larger, it won't be able to do that anymore. Here's the