this is for the client :
import java.net.*;
import java.io.*;
public class tcpclient
{
public static void main(
String args[]) throws Exception
{
Socket soc = new Socket("mac3",8001);
PrintWriter out = new PrintWriter(new OutputStreamWriter(soc.getOutputStream()));
BufferedReader inn = new BufferedReader(new InputStreamReader(soc.getInputStream()));
DataInputStream get = new DataInputStream(System.in);
System.out.println(inn.readLine());;
String str = get.readLine();
out.println(str);
out.flush();
// TO RECEIVE
//String mess = inn.readLine();
//System.out.println(mess);
}
}
this is for the server :
import java.net.*;
import java.io.*;
public class tcpserver
{
public static void main(String args[]) throws Exception
{
ServerSocket soc = new ServerSocket(8001);
System.out.println("server is ready");
Socket abc=soc.accept();
PrintWriter out = new PrintWriter(new OutputStreamWriter(abc.getOutputStream()));
BufferedReader inn = new BufferedReader(new InputStreamReader(abc.getInputStream()));
out.println("Connected");
out.flush();
System.out.println("Ready to read data");
String mess = inn.readLine();
System.out.println("message :"+mess+"from :"+abc.getInetAddress().getHostName());
} }
hope this helps .