Re: Access the Same Socket
Re: Access the Same Socket
THANKS json for your concern...
but iam only able to write the client side because i didnot have the access to modify anything on the server
so i need only to have 2 classes "as Client" one open in it the socket with server
and the other class access this socket and write / read anything to.from the server through it.....plz help...i appreciate you so much
Re: Access the Same Socket
I take it these two classes are in the same client and not two different programs on start up?
Something like this would possibly work.
Code :
public class MainClass {
public static void main(final String... arguments) {
try{
final Socket socket = new Socket("10.10.10.1",5); // Open the connection to the server
final Client client = new Client(socket); // Create a client using our client class passing in the socket
final Thread thread = new Thread(client); // Create a thread to run the client
thread.start(); // Start the client thread
} catch (Throwable throwable) {
throwable.printStackTrace();
}
}
}
public class Client implements Runnable {
private Socket socket;
public Client(final Socket socket) {
this.socket = socket; // Store a reference to the socket
}
public void run() {
// Write to the socket and do whatever you like
}
}
// Json
Re: Access the Same Socket
Really thanks sooooooooooo much Json...u r very good person
but simply i want two .java classes
1.MainClass.java
Create Socket with Server
2.ClientCaller.java
Access the Opened Socket Of MainClass.java
these 2 .java are separately in 2 files but in the same package....i knew that i talk alot about my problem..but really wana its solution
and thaaaaaaaaaaaaaaaaaaaank u very much for your help :)
Re: Access the Same Socket
Just use the code I posted above then, or even do it without the threading.
// Json