//server side
import java.io.*;
import java.net.*;
class clientsoc1{
public static void main(
String args[]) throws Exception
{
InetAddress i=InetAddress.getLocalHost();
String str=new String();
String strt=new String();
Socket soc=new Socket(i,4444);
System.out.println(soc.getInetAddress());
BufferedReader is=new BufferedReader(new InputStreamReader(soc.getInputStream()));
DataOutputStream os=new DataOutputStream(soc.getOutputStream());
BufferedReader bs=new BufferedReader(new InputStreamReader(System.in));
str=bs.readLine();
int i1=str.length();
strt=is.readLine();
os.writeChars(str);
os.write(10);//change made
System.out.println(strt);
os.flush();
is.close();
os.close();
soc.close();
}
}
//client side
import java.net.*;
import java.io.*;
class Serversoc1{
public static void main(String args[]) throws Exception
{
String str1=new String();
ServerSocket scos=new ServerSocket(4444);
Socket soc1=scos.accept();
System.out.println(soc1);
BufferedReader br=new BufferedReader(new InputStreamReader(soc1.getInputStream()));
DataOutputStream ds=new DataOutputStream(soc1.getOutputStream());
System.out.println("on server now");
str1= br.readLine();//change done
System.out.println(str1);// prints on the server side
ds.writeChars(str1);
ds.write(10);//change done
ds.flush();
br.close();
ds.close();
soc1.close();
}
}
it is still not working.please try it out.i've been working on it for a long time.but still ,if the message is not send back to the client
then it works properly the message is printed on the server side.