Discussion:
[JSch-users] How to get Socket used in Session ?
Danisment Gazi Unal
2014-04-19 17:35:49 UTC
Permalink
Hello!

I'm trying to use com.jcraft.jsch.SocketFactory() to create Socket. I need
to get Socket. I add getSocket() as below:

public class SSHSocketFactory implements com.jcraft.jsch.SocketFactory {

private SSHSocket gSocket = null;

public synchronized Socket createSocket(String host, int port) throws
IOException, UnknownHostException {

gSocket = new SSHSocket(host, port);
return gSocket;
}

.....

public SSHSocket getSocket() {

return gSocket;
}
}


If the same socket factory is called multiple times(including by Jsch
internally too), then It always returns the last socket.

I guess I need a method like createSocket(id,host,port) to get it by
getSocket(id).

How can I safely get Socket created by specic host,port pair ?

thanks in advance...
Danisment Gazi Unal
2014-04-19 17:44:54 UTC
Permalink
If it's not possible to get Socket safely by
com.jcraft.jsch.SocketFactory(), is it possible to pass a Sockect object to
Session ? Or, any other method to handle Socket object used in Session ?

thanks.
Post by Danisment Gazi Unal
Hello!
I'm trying to use com.jcraft.jsch.SocketFactory() to create Socket. I need
public class SSHSocketFactory implements com.jcraft.jsch.SocketFactory {
private SSHSocket gSocket = null;
public synchronized Socket createSocket(String host, int port) throws
IOException, UnknownHostException {
gSocket = new SSHSocket(host, port);
return gSocket;
}
.....
public SSHSocket getSocket() {
return gSocket;
}
}
If the same socket factory is called multiple times(including by Jsch
internally too), then It always returns the last socket.
I guess I need a method like createSocket(id,host,port) to get it by
getSocket(id).
How can I safely get Socket created by specic host,port pair ?
thanks in advance...
Loading...