Below code includes both client and server code.... I am trying to read message from client and display it on server and vice versa......Problem i am facing is both the codes are executin but messages are not getting displayed ....help me
import java.io.*;
import java.net.*;
class Client
{
public static void main(String args[])
{
try
{
Socket s=new Socket("127.0.0.1",1122);
OutputStream os=s.getOutputStream();
BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(os));
bw.write("Hii Server");
InputStream is=s.getInputStream();
DataInputStream dis=new DataInputStream(is);
System.out.println(dis.readLine());
s.close();
os.close();
is.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}
//Server Code
import java.io.*;
import java.net.*;
class Server
{
public static void main(String args[])
{
try
{
ServerSocket ss=new ServerSocket(1122);
System.out.println("Waiting For Connection ......");
while(true)
{
Socket s=ss.accept();
System.out.println("Connection got accepted.....");
System.out.println("Client Data being read.....");
InputStream is=s.getInputStream();
DataInputStream dis=new DataInputStream(is);
System.out.println(dis.readLine());
OutputStream os=s.getOutputStream();
BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(os));
bw.write("Hiii client");
dis.close();
s.close();
}
}
catch(Exception e)
{
System.out.println("Error");
}
}
}