Java program development small experience - issues that will appear using ObjectStream

xiaoxiao2021-03-06  107

1. ObjectInputStream and ObjectOutputStream sequential issues In Network Communication, hosts and clients use ObjectInputStream to establish object communication with ObjectOutputStream, you must pay attention to declare the order of these two objects. Such as: The host has established ObjectInputStream and establishes ObjectOutputStream, and the corresponding client should first establish ObjectOutputStream to establish ObjectInputStream, otherwise it will cause both parties to wait for data to cause a deadlock. The reason is that the establishment of the ObjectInputStream object is to receive a certain HEADER data before receiving these data. The following is a description Creates JAVA API documentation of an ObjectInputStream that reads from the specified InputStream. A serialization stream header is read from the stream and verified. This constructor will block until the corresponding ObjectOutputStream has written and flushed the header. To prevent this, therefore dead ObjectInputstraem, ObjectOutputStream, ObjectOutputStream, and ObjectOutputStream, which must be used in order. 2. ObjectInputStream The problem that the non-ObjectOutputStream data is used in communication between the ObjectInputStream and the ObjectOutputStream object communication, assumes that the client program has an error, transmits data sent by non-ObjectOutputStream package (such as sending a number or string to the host), then host After the end ObjectInputStream receives the error data, it cannot be automatically corrected, and the data is received directly and is in a blocking state, resulting in failure of communication. No solution has been found. The current thinking is to write your own ObjectStream class. 3. Solution to the version problem When using ObjectStream, you will have an additional serial number static final long waitVersionuid = .... Manually add this domain to avoid the problem of version differences. The calculation of the object serial number can be calculated by SDK's Serialver.

转载请注明原文地址:https://www.9cbs.com/read-101150.html

New Post(0)