Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need tips for socket communication problem 1

Status
Not open for further replies.

frag

Programmer
Dec 7, 2000
321
GB
Hi!

I have to realize a client-server-application with secure socket layer. The technic is no problem, I already have successfully build a small demo (a chat). But I am facing some other problems right now:

The client should be able to send a request to the server that will let the server call some shellscripts or make some database operations. But I can only send strings over this socket-connection. I am looking for a comfortable way to send the proper commands from the client and receive status-messages as well as results from a SQL-select-statment from the server.

Could someone please give me some hints? I know how to do all this stuff like exec a shellscript, make database-connections, etc. But I really have no clue how this communication can be solved in a handsome and comfortable way.

Cheers

frag

patrick.metz@epost.de
 
If you want to send objects over a socket then you need to serialize the object, which in effect creates a byte[] array. You can then retrieve this (maybe as a ByteArrayInputSteam). If you want to send the results from a db call, then the easiest way to do it is write to a file, then read in the file as a byte array, and send this.

However, you may want to look at RMI or CORBA, as these technolgies (built on TCP/IP socket communication) simplify the protocols required fro socket comms.
 
Thx, I use now the ObjectInputStream and ObjectOutputStream classes and have written my own serialized objects.

But if I try to send more than one object I get this exception from the server:

java.io.StreamCorruptedException: InputStream does not contain a serialized object

But all of my three objects are serialized and I don't put anything else in the stream. What I do is to read the Object from the stream and then try to cast the object into the proper objects (my serialized ones) with the help of try and catch logic. What am I doing wrong?

Please help.... [sadeyes]


patrick.metz@epost.de
 
Ok, forget it... I have always instantiate a new stream object in the server's client-handle-thread and therefore the object send from the client could not be picked up by the server... a tipical noob mistake *grrr*

patrick.metz@epost.de
 
Cheers for the star ....

If you serialize objects, the object you serialize must implement the Serializable interface ... simply -

public class MySerializableObject implements Serializable {
// methods/ constructors etc ....
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top