Hey everyone,
I've hit a wall with a project that I'm working on and I was hoping you guys might be able to help me out.
I am creating a socket and keep the socket open to read/write so that the program can react as data is changed live. I created a second class running in a seperate thread that I would like to be able to use the socket in the first class to write data from time. Does any body know how I can do that?
Kind of what I'm trying to do:
public class ClassA { public void MethodA() { Socket socket = new Socket(server, port); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())); BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream())); } } public class ClassB { public void MethodB() { // Here I'd like to either use the BufferedWriter to write to the socket, or some how call a method from ClassA to write to the existing socket } }