Struggling with what is probably simple syntax to 'retrieve' a reference to a socket which is already connected so I can 'reuse' it.
This code works fine (the socket stays open once created)-
String thisIP = var4.getString("ipaddress");
try {
if ((this.socket == null || !this.socket.isConnected()) && this.running == 0) {
this.running = 1;
socket = new Socket(thisIP, 2001);
}
In a separate java class / file I need to 'retrieve' and reuse the socket, so something like -
queryStatus of the socket connected to "192.168.150.210" and return the entire socket reference (IP address, port number and locally bound IP port) so I can reuse it in a PrintWriter statement
new PrintWriter(s.getOutoutStream())
where s is the socket reference
I assume I require some sort of array to store all the previously created socket references?
I cant just create a new socket and use that because the third party IP device (a LAN module) only allows 1 TCP client connection.
Thoughts appreciated. Regards Ralph