B
Bruce Lee
I need to build a proxy server that will keep alive an asynchronous
connection with a client and a remote server until the client closes. The
type of data is ASCII.
I've tried this code it doesn't work?
//needs to keep client socket & server socket open and wait for messages
from client and returns from server
class CommSession extends Thread{
Socket clie;
Socket serv;
CommSession(Socket clie,Socket serv){
this.clie=clie;
this.serv=serv;
}
public void run(){
try{
System.out.println("set up session on "+serv);
while(!clie.isClosed()){
DataInputStream in = new
DataInputStream(clie.getInputStream());
DataOutputStream out = new
DataOutputStream(serv.getOutputStream());
String cmd="";
while((cmd=in.readLine())!=null){
out.writeBytes(cmd+"\n");
System.out.println("TO-SERVER:"+cmd);
}
DataInputStream in2 = new
DataInputStream(serv.getInputStream());
DataOutputStream out2 = new
DataOutputStream(clie.getOutputStream());
String cmd2="";
while((cmd2=in2.readLine())!=null){
out2.writeBytes(cmd2+"\n");
System.out.println("TO-CLIENT:"+cmd2);
}
}
}catch(Exception ss){ss.printStackTrace();}
}
}
connection with a client and a remote server until the client closes. The
type of data is ASCII.
I've tried this code it doesn't work?
//needs to keep client socket & server socket open and wait for messages
from client and returns from server
class CommSession extends Thread{
Socket clie;
Socket serv;
CommSession(Socket clie,Socket serv){
this.clie=clie;
this.serv=serv;
}
public void run(){
try{
System.out.println("set up session on "+serv);
while(!clie.isClosed()){
DataInputStream in = new
DataInputStream(clie.getInputStream());
DataOutputStream out = new
DataOutputStream(serv.getOutputStream());
String cmd="";
while((cmd=in.readLine())!=null){
out.writeBytes(cmd+"\n");
System.out.println("TO-SERVER:"+cmd);
}
DataInputStream in2 = new
DataInputStream(serv.getInputStream());
DataOutputStream out2 = new
DataOutputStream(clie.getOutputStream());
String cmd2="";
while((cmd2=in2.readLine())!=null){
out2.writeBytes(cmd2+"\n");
System.out.println("TO-CLIENT:"+cmd2);
}
}
}catch(Exception ss){ss.printStackTrace();}
}
}