This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes JDBC and the fly likes Storing Socket object in database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Storing Socket object in database" Watch "Storing Socket object in database" New topic
Author

Storing Socket object in database

Raghav Mathur
Ranch Hand

Joined: Jan 12, 2001
Posts: 641
HI
Is it possible to store a Socket Object in the database(MySql) which can be retrieved later when required.
when the server accpets a connection , it spawns a new socket for each connection so that the required input/output stream can be opened .
Now i want to store this socket object and mantain a list so that when a pirticular socket is being selectd from the database , then the inpu/output stream should open for that pirticular socket only .
I hope i,am clear enough
Please guide me a bit
Thanks in advance


Raghav.
Raghav Mathur
Ranch Hand

Joined: Jan 12, 2001
Posts: 641
is it possible ?
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

1) I really don't think so
2) I really hope not.
Sockets aren't distributable ie you can't move it from one machine to another. It isn't Serializable etc. It represents an active connection between your machine and the remote machine, and the connection needs to be supported at both ends. If you did manage some way to persist it, your side would no longer be active and the remote computer would disconnect. If you found away to recreate the Socket, the other end would no longer exist.
I saw a while ago someone trying to do something similar in trying to synchronize requests to a server, and it failed horribly.
Dave
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

From browsing your other thread, if the remote machine will accept connections you can store the socket settings as a host and port in the database then attempt to reconnect with the client when ready. You would be creating a new Socket each time, as opposed to persisting the Socket instance.
Raghav Mathur
Ranch Hand

Joined: Jan 12, 2001
Posts: 641
That's what i,am doing :
1) A client connects to the actual server.
2) The server retrives the IP and the port of the connected client and stores them in the database.
3) The server sends back the port from which the client is connected so that the client can now listen for incomming connections on that pirticular port returned by the server.
At this stage the link between the client and server closes and the client is now ready to accept just one connection.
4) Finally a third interface (i call it external client)which sees all the conneted clients and on selecting a pirticular client it gets the coresponding ip and port of that client ( which is now ready to listen for just one connection so that the conversation with the external client begins).
The external client makes a socket connection to the client( which is now listening for a connection) but couldn't make it ?
I tried to ping the machine on which the client( which was now listening for a connection) but it didn't ping .
I know unless it doesn't ping my socket connectivity won't take place but is my overall design ok?
I've tested this application locally and it works . What could be the reason that it doesn't work on the internet( besides the pinging thing).
I don't even know why the hell it was not pinging whereas i tried the other way round.I tried to ping from the machine where the client( which is listening for connections) is running to the machine where the external client is trying to make connection to the connected clients and it did ping .
What do you say ?
Once again ... this application works fine locally ( on our Local Area Network ) .
Thanks in advance
Originally posted by David O'Meara:
From browsing your other thread, if the remote machine will accept connections you can store the socket settings as a host and port in the database then attempt to reconnect with the client when ready. You would be creating a new Socket each time, as opposed to persisting the Socket instance.

[ July 09, 2003: Message edited by: raghav mathur ]
[ July 09, 2003: Message edited by: raghav mathur ]
[ July 10, 2003: Message edited by: raghav mathur ]
Raghav Mathur
Ranch Hand

Joined: Jan 12, 2001
Posts: 641
David
I hope i,am clear enough
It would be better if we continue this discussion on the Socket forum . PLease follow the link given below .
Thanks in advance
Raghav Mathur
Ranch Hand

Joined: Jan 12, 2001
Posts: 641
I,am yet waiting for you
Please help me out .
I've really got stuck . This is very urgent .
Thanks in advance
 
Don't get me started about those stupid light bulbs.
 
subject: Storing Socket object in database