When I declare in Java
Socket s = new Socket((String)null, 12345);
Does this actually open a socket and use system and network resources, or is that deferred until I attach an input/output buffer? I would like to create a Socket object at the start of my program that is all set up to connect to the server, and just open/close it as necessary, instead of having to pass an address and port around (it seems cleaner), but not if it means the port will be open the entire time.
EDIT
It seems from the answers that this will not work like I wanted. How can I create a closed socket that is all set up with address and only needs to connect?
http://docs.oracle.com/javase/6/docs/api/java/net/Socket.html#Socket(java.net.InetAddress,%20int) <- it depends on the constructor you use. For the constructor you have specified, it connects.
According to http://docs.oracle.com/javase/7/docs/api/java/net/Socket.html#Socket(java.lang.String,int) ,the way you are initializing your object it will be connected.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With