objectinputstream


Performance issue using Javas Object streams with Sockets

守給你的承諾、 提交于 2020-01-20 05:46:48
问题 I'm trying to do local IPC using Sockets and Object streams in Java however I'm seeing poor performance. I am testing the ping time of sending an object via an ObjectOutputStream to receiving a reply via an ObjectInputStream over a Socket. Here's the Requestor: public SocketTest(){ int iterations = 100; try { Socket socket = new Socket("localhost", 1212); ObjectInputStream objectInputStream = new ObjectInputStream(socket.getInputStream()); ObjectOutputStream objectOutputStream = new

new ObjectInputStream() blocks

孤人 提交于 2020-01-09 05:01:26
问题 public class SerProg { static ServerSocket ser=null; static Socket cli=null; static ObjectInputStream ins=null; static ObjectOutputStream outs=null; public static void main(String[] args) { try { ser=new ServerSocket(9000,10); cli=ser.accept(); System.out.println("Connected to :"+cli.getInetAddress().getHostAddress()+" At Port :"+cli.getLocalPort()); ins=new ObjectInputStream(cli.getInputStream()); outs=new ObjectOutputStream(cli.getOutputStream()); String str=(String)ins.readObject(); }

How do I handle an Invalid Stream header Exception: 00000001?

て烟熏妆下的殇ゞ 提交于 2020-01-06 12:50:58
问题 java.io.StreamCorruptedException: invalid stream header: 00000001 Simple Project I found this, and this seems to be a common problem. If you write to a directory with files and then manually deleted one later, you will end up getting this error. java.io.StreamCorruptedException: invalid stream header: 00000001 at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:806) at java.io.ObjectInputStream.<init>(ObjectInputStream.java:299) The code: private void deserialize(File input){

Java - ClassNotFound Exception when working with ObjectInputStream and ArrayList

巧了我就是萌 提交于 2020-01-05 12:10:13
问题 I'm trying to move the contents of an ArrayList from the client to the server. When trying to readObject() the input I receive a ClassNotFoundException. Here is my code, along with the stack trace: Client: ArrayList<Person> people = new ArrayList<Person>(); ObjectOutputStream output = new ObjectOutputStream(socket.getOutputStream()); for (Person p : people) { output.writeObject(p); } Server: ArrayList<Employee> employees = new ArrayList<Employee>(); ObjectInputStream input = new

Sending Java object of an unknown class

此生再无相见时 提交于 2020-01-04 13:57:47
问题 searching for a long time, but didn't find any answer on that one: I have a server and I have a client. The server should receive an object via ObjectInputStream and ObjectOutputStream . That already works for any class , known on the server. Now I want to send an Object of a class the server doesn't know. He only knows the interface of that class. And that obviously fails... How can I avoid the ClassNotFoundException ? I thought interfaces were the solution. I only want to access the

Cannot create ObjectInputStream with InputStream for a Bluetooth Socket on the Android Platform

谁都会走 提交于 2020-01-01 02:51:10
问题 I am writing a multiplayer game for Android phones. Communication is via Bluetooth. I have managed to send bytes from one phone to the other using the input / output stream. Since I need to be able to transfer objects I want objectstreams. However, when I try to create an Objectstream with my streams, my program hangs on the instruction. public class ConnectedThread extends Thread { private static final String TAG = "Connected Thread"; private final BluetoothSocket mmSocket; private final

send a serializable object over socket

情到浓时终转凉″ 提交于 2019-12-25 18:14:57
问题 I have a strange problem to send a serializable object that I have created over socket. In fact if I run the server and the client in the same machine it works well but if the server and the client are in different machines the readen object in the server side is empty (with size equal to zero) Any one have an idea to fix that ? (the code is bellow) Server: public static void main () { ... InputStream is = mysocket.getInputStream(); ObjectInputStream ois = new ObjectInputStream(is); ArrayList

Getting Progress of ObjectOutputStream/ObjectInputStream

本小妞迷上赌 提交于 2019-12-25 15:54:37
问题 I recently figured out how to use ObjectOutputStream and ObjectInputStream to send objects over a simple Java socket connection between a server and a client. I was wondering if I wanted to transfer an object that might be large in size, for example an image, is it possible to put a thread that keeps track of the progress of how much data has been sent/received? If the answer to this question isn't very direct, could someone explain how I might go about doing something similar? Thanks in

Getting Progress of ObjectOutputStream/ObjectInputStream

别说谁变了你拦得住时间么 提交于 2019-12-25 15:53:34
问题 I recently figured out how to use ObjectOutputStream and ObjectInputStream to send objects over a simple Java socket connection between a server and a client. I was wondering if I wanted to transfer an object that might be large in size, for example an image, is it possible to put a thread that keeps track of the progress of how much data has been sent/received? If the answer to this question isn't very direct, could someone explain how I might go about doing something similar? Thanks in

Workaround java.io.EOFException cause by ObjectInputStream [duplicate]

二次信任 提交于 2019-12-25 08:07:38
问题 This question already has answers here : java.io.FileNotFoundException when creating FileInputStream (2 answers) Closed 2 years ago . For my application I want to use a Map to act as a database. To save and load a map, I am writing/reading it to/from database.ser using this 2 methods: private synchronized void saveDB() { try { fileOut = new FileOutputStream(db); out = new ObjectOutputStream(fileOut); out.writeObject(accounts); fileOut.close(); out.close(); } catch (FileNotFoundException e) {

工具导航Map