I have created two socket file,But it is not working in proper way.
please let meknow where the porblem is.
TCPClient.java
import java.io.*;
import java.net.*;
class TCPClient
{
public static void main(String ar[]) throws Exception
{
String fromserver;
String toserver;
Socket clientsocket=new Socket("localhost",10000);
BufferedReader infromuser=new BufferedReader(new InputStreamReader(System.in));
PrintWriter outtoserver=new PrintWriter(clientsocket.getOutputStream(),true);
BufferedReader infromserver=new BufferedReader(new InputStreamReader(clientsocket.getInputStream()));
while((toserver=infromuser.readLine())!=null)
{
toserver=infromuser.readLine();
outtoserver.println(toserver);
fromserver=infromserver.readLine();
System.out.println("received"+fromserver);
}
clientsocket.close();
}
}
TCPServer.java
import java.io.*;
import java.net.*;
class TCPServer
{
public static void main(String ar[]) throws Exception
{
String toclient;
String fromclient;
ServerSocket server=new ServerSocket(10000);
System.out.println("Waiting for client on 10000");
Socket connected=server.accept();
System.out.println("connection succ");
BufferedReader infromuser=new BufferedReader(new InputStreamReader(System.in));
PrintWriter outtoclient=new PrintWriter(connected.getOutputStream(),true);
BufferedReader infromclient=new BufferedReader(new InputStreamReader(connected.getInputStream()));
while((toclient=infromuser.readLine())!=null)
{
fromclient=infromclient.readLine();
System.out.println("received from client"+fromclient);
toclient=infromuser.readLine();
outtoclient.println(toclient);
}
connected.close();
}
}
I dont know the problem.
It is not subsequently chat with server.This is simple client server chat application.