Link to home
Start Free TrialLog in
Avatar of richardsimnett
richardsimnett

asked on

Writing a Hashtable to a socket

Hello,
I need to know how to write and read hashtables passed over a socket connection. The program basically takes data from a database, converts each row to a hashtable and then needs to connect to several servers, and pipe this information to them. A hashtable for me is the easiest way to do this. Can someone show me how to accomplish this?

Worth 500 points.

Thanks,
Rick
SOLUTION
Avatar of BogoJoker
BogoJoker

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mick Barry
Use ObjectInputStream/ObjectOutputStream
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of BogoJoker
BogoJoker

JAlmanaac on Serializing and Unserializing an object:
http://javaalmanac.com/egs/java.io/SerializeObj.html

Pretty much exactly what objects said.  But the site is a great reference if you did not know about it.

Joe P
Another approach is to use RMI and it will handle the job of creating sockets/ threads, serializing/ deserializing objects for you. Make sure the object (message) definition is available on both sides (meaning the class whose instances you are putting in the hash-table).
I just gotta ask somebody.
Is it me or does the java API look like they are using some CSS and Images now?
I expect both of you have looked at that site tons of times, doesn't it look different! Maybe its just me
You mean the Java TA here or the Java API doc on Sun's site?
Java API, but I was wrong, I was just on the SerializedForm screen, I had never been on it before and there was just a lot of big text and colors...  Normal classes are normal, I was just on a weird page.

Joe P
Avatar of richardsimnett

ASKER

objects,
Im not familiar with serializable, the keys and values are strings across the board.

Thanks,
Rick
can you give me an example of what this would look like so I can familiarize myself with it?


Thanks,
Rick
nevermind I got it now... Strings are serializable, and that just adds methods that are in place to read / write them.

Im going to split points.

Thank,
Rick
>> Im not familiar with serializable, the keys and values are strings across the board.

Primitive data types and many standard Java classes are serializable by default. If that's what you use in your own class, you should be fine