
how to invoke the code from JTextArea to Socket

package magesh;
import java.net.Socket; import java.io.DataInputStream; import java.io.PrintStream;
public class Client {
public Client(){
DataInputStream dsc,dkb;
PrintStream ps;
try{
System.out.println("Client look at 10001");
Socket s = new Socket("localhost",10001);
System.out.println("Connect establish by client");
dsc = new DataInputStream(s.getInputStream());
dkb = new DataInputStream(System.in);
ps = new PrintStream(s.getOutputStream());
while(true){
System.out.println("Client : ");
String s1 = dkb.readLine();
ps.println(s1);
String s2 = dsc.readLine();
System.out.println("Server : "+s2);
if(s2.equalsIgnoreCase("bye")||s1.equalsIgnoreCase("bye")){
break;
}
}
}catch(Exception ex){
System.out.println("Error : "+ex.getMessage());
}
}
public static void main(String[] args) {
new Client();
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.