Solved

java client receive a packet from delphi server

Posted on 2003-10-26
3
238 Views
Last Modified: 2010-03-31
I want to receive a packet from server.It's seemed that readObject() cann't be used,when server is a java server,it can get the right class,but   when server is a delphi server,it shows "not a serilizable
inputstream",how could i get packet from delphi server?
0
Comment
Question by:lingwangbochen
  • 2
3 Comments
 
LVL 15

Expert Comment

by:jimmack
ID: 9625491
If you use readObject(), then your client is expecting a Java object to come across the link (including information about the methods, attributes etc.).

You say that you want to receive a "packet".  What is the format of the packet?

Can you read it as a byte[] sequence and reconstruct it on the Java client into an object there?
0
 

Author Comment

by:lingwangbochen
ID: 9625603
the "packet" include the seqno of the packet,length of the packet,content of the packet...
for example:
   public int plength;
   int commandid;
   int seqno;
   int bindtype;
   String user;                      //can change to another content
   String passwd;                 //can changeable
it is sended from delphi using" SendBuf " function,
I can receive a char use read() or read(char[],int,int) of Class java.io.BufferedReader,i don't know how to reconstruct it and
 the packet is changeable,so i think read as object perhaps be simple. i only receive some char now.Could you help me?
 
0
 
LVL 15

Accepted Solution

by:
jimmack earned 125 total points
ID: 9625651
You would probably be better using a DataInputStream instead of a BufferedReader.  This would allow you to use methods like readInt(), readUTF() etc.

(readUTF() is for reading Strings).

If the packet contains different data, is there a way to determine the format of the data that is expected across the link (like an identifier or something).

In this particular case, you need a class to store the attributes you have described, then you could read them from the stream using:

MyObject myObj = new MyObject();
DataInputStream dis = new DataInputStream(  < your raw input stream here > );
myObj.setPlength = dis.readInt();
myObj.setCommandid = dis.readInt();
myObj.setSeqno = dis.readInt();
myObj.setBindtype = dis.readInt();
myObj.setUser = dis.readUTF();
myObj.setpasswd = dis.readUTF();

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now