tags:

views:

262

answers:

4

I want to store sockets in my database and retrieve them also. But sockets are not serializable so I was unable to do this.

How can I store sockets in a database?

+18  A: 

What about the socket do you wish to store in the database? A socket itself represents something that cannot be stored in the databsae, but perhaps you can fetch the important attributes of a socket -- endpoints IP addresses, ports, and maybe some other important attributes if any -- and store those in the database as a proxy for the socket itself.

Eddie
A: 

How do you want to store a socket in a database? Do you mean a data structure?

If it is a data structure you mean, then you could just store the sockets in a vector.

Example:

Vector yourNewPlaceToStoreSockets = new Vector();
yourNewPlaceToStoreSockets.add(yourSocketObject);

If you could be a bit more descriptive it would help me answer you better.

fmsf
this is a random example, It was the best answer i could take for a question such as the one you gave
fmsf
Please consider using a generic collection, i.e. Vector<Socket>. If you don't need a synchronised collection, you might be better off using an ArrayList<Socket>.
Rob
A: 

A socket that your program has access to is a transient entity that will be relinquished. What do you mean by storing it in the databaqse? What are you trying to do?

Do you actually mean a database (like an external database management system) or a data structure? Because you could place it in a collection.

Uri
+2  A: 

You need to think about what you really need to store in the database that represents the "conversation" with the client in your particular application.

For example, it could be a (securely generated) random number/session ID allocated on the server and which the client passes up as a cookie. It might be an IP address/remote port, bearing in mind that they should be regarded as temporary.

Neil Coffey