• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Sending a HashMap over a Server socket

 
Ardel Grider
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a way to make a Server Socket output a Hashmap? I am trying to figure out the best way to pull the data from the Producer, which is on a server, to the main program, which is on a desktop. I have made it to where the producer will put all the data into a Hashmap and the Main program will break all of the data down. But I am experimenting with Sockets and it is telling me the data needs to be an int. What would be the best way to go about this if a socket is not the correct method?
 
Ardel Grider
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am sorry for the terrible title. I meant to update it before posting and forgot. And it seems I either can't find the edit button or it doesn't exist. T_T
 
Paul Clapham
Sheriff
Posts: 21548
33
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"The data needs to be an int"... that isn't quite right. A socket knows nothing about Java, all it knows about is bytes being transmitted. So to send a HashMap over a socket connection you need to serialize it into a series of bytes, and send those bytes. The most straightforward way to do that is to use the serialization which is built into Java and use ObjectOutputStream to send the object and ObjectInputStream to receive it. There are other ways to serialize Java objects but now that you are looking in the right direction you can search for those if you like.

(As for infelicitous posting decisions, your post didn't look like anything to do with JDBC so I moved it to our Sockets forum. I will edit your title to something which I think is better, but if you don't think it's better then post again with your idea.)
 
Ardel Grider
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Paul, this really helps alot. And sorry for posting in the wrong section. I am pretty new here and didn't know there was a socket section. Thanks again
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic