Acess to Threaded Class

I have the following code:

Server.java:

public class Server
{
	public Thread InNetwork[] = new Thread[10];
	
	public static void main(String Args[])
	{
		new Server();
	}
	public Server()
	{
		InNetwork[0] = new Thread(new InNetwork());
	}
}

InNetwork.java:

public class InNetwork implements Runnable
{
	public int iClientH = -1;
	public InNetwork()
	{
		
	}
	public void run()
	{
		while(true)
		{
			
		}
	}
}

how can i access for example to variable iClientH from Server class ?

Wow what a mess you’ve got there, pal . Why are you naming your Thread array with the same name of you InNetwork class ??


	public Thread InNetwork[] = new Thread[10];  // ???  

To answer your question I’ll change the name of this array to ‘threads’.
To access the variables you have to keep a reference from the instance you passed to the Thread:


public class Server
{
	public Thread threads[] = new Thread[10];
	
	public static void main(String Args[])
	{
		new Server();
	}
	public Server()
	{
                InNetwork in = new InNetwork();
		threads[0] = new Thread(in);
                in.iClientH = 12345;
	}
}

Other than that, I suggest you looking into java basics first, before writing Client/Server applications .

Yeeeaaaaah…

Definitely definitely do not work with multithreading and client/server stuff until you know how to write an accessor method… Man, you really need to start from the beginning. Ground zero. Write Hello World.