hey all;
please i have a problem...and wana your help and support
- I made client application to connect to a server
- Client application contains multiclass:
1.Main Class
Open In It Socket With Server
package GlobalSocketPackage;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
public class MainClass implements Runnable
{
public static Socket server;
public static BufferedReader br;
public static BufferedWriter bw;
/////////////////////////////////////////////////////////
public MainClass() {
System.out.println("Default Con.");
}
/////////////////////////////////////////////////////////
public MainClass(String m) {
try{
server = new Socket("10.10.10.1",5);
}
}catch(Exception ex){System.out.println("error"+ex);}
}
/////////////////////////////////////////////////////////
public void WriteRead() throws IOException, InterruptedException
{
br = new BufferedReader(new InputStreamReader(server.getInputStream()));
bw = new BufferedWriter(new OutputStreamWriter(server.getOutputStream()));
Thread th=new Thread();
th.start();
}
//////////////////////////////////////////////////////////
public static void main(String arg[])throws IOException, InterruptedException
{
MainClass Client=new MainClass("");
Client.WriteRead();
while(true)
try{
System.out.println("Connected");
}catch(Exception exx){}
}
public void run() {
throw new UnsupportedOperationException("Not supported yet.");
}
}
2.Call Class
Try through it to Access The Same Socket Of Main Class
--> What I want is to make 2 classes.....package GlobalSocketPackage;
//Problem1
//Note: by using this class i cannot send any data on the opened socket ("10.10.10.1",5)
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
public class CallClass1 {
public static void main(String args[])throws IOException, InterruptedException
{
try{
//Just To Knew Current Opened Port
MainClass mc= new MainClass();
mc.WriteRead.bw = new BufferedWriter(new OutputStreamWriter(MainClass.server.getOutputStrea m()));
mc.WriteRead.bw.write("Send On the Same Socket");
mc.WriteRead.bw.flush();
}catch(Exception exx){}
}
}
// Need to send Data on the same Opened Socket from another Class In same Package Or Application
One has the Opened Socket
and the other one use this Socket to send output Streams through it without make reconnection on the same socket with the server
plz help .. thanks so much