I am writing a code that will simulate the Kerberos protocol in Java. I have a server class and a client class. But some content is static and other content is not, plus sockets, I’m mixed up to say the least. The details of the protocol I believe are arbitrary in this question.
I have a Server class, which calls a ServerThread class:
public class Server{
public void someMethod(){ /* some code */ }
public static void main(String args[]){
ServerSocket serverSocket = new ServerSocket(port);
new ServerThread(serverSocket.accept()).start();
}
}
public class ServerThread extends Thread{
/* constructor (takes serverSocket from Server) */
this.parent.someMethod();
/* That would call someMethod() from the parent class Server instance
* that instantiated this.
*/
}
The part of the Server class that instantiates the ServerThread was given to me, I have to use it as is. The someMethod() method I wrote myself, that’s the one I want to use from ServerThread. Is there a way to do this call the line of code that says this.parent.someMethod();? If I can, is there a way to access both classes from a single controller class, or does the static content vs. non-static content ruin that idea?
Can you pass a reference to an instance of the
Serverto theServerThread(via getter/setters or modifing the constructor)? If so, pass the reference and then you can callserver.someMethod(), assumingserveris the variable name.If not, would your
someMethod()make sense as a static method? If it is safe to make it a static method, you can doServer.someMethod().