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
richardsimnettAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

BogoJokerCommented:
Hi richardsimnett,

A hash table is serializable, you could serialize the table, send the data over the socket, then unserialize the table on the other side.

Joe P
0
objectsCommented:
Use ObjectInputStream/ObjectOutputStream
0
objectsCommented:
to send:

ObjectOutputStream out = new ObjectOutputStream(socket.getOutputStream());
out.writeObject(map);

too recieve:

ObjectInputStream in = new ObjectInputStream(socket.getInputStream());
Map map = (Map) in.readObject();



You'll need to ensure all the objects in your map (keys and values) implement Serializable

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

BogoJokerCommented:
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
0
Mayank SAssociate Director - Product EngineeringCommented:
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).
0
BogoJokerCommented:
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
0
Mayank SAssociate Director - Product EngineeringCommented:
You mean the Java TA here or the Java API doc on Sun's site?
0
BogoJokerCommented:
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
0
richardsimnettAuthor Commented:
objects,
Im not familiar with serializable, the keys and values are strings across the board.

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


Thanks,
Rick
0
richardsimnettAuthor Commented:
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
0
Mayank SAssociate Director - Product EngineeringCommented:
>> 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
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.