i wrote the following code..but i am not able to create multi client code
import java.io.*;
import java.net.*;
class ThreadClient
{
public static void main(String args[]) throws IOException
{
Socket soc=new Socket("127.0.0.1",1445);
System.out.println("Client connected to the server");
//thread creation
SendThread sendThread=new SendThread(soc);//creating object
Thread thread=new Thread(sendThread);//creating thread object
thread.start();//starting thread
RecieveThread recieveThread=new RecieveThread(soc);//creating object
Thread thread1=new Thread(recieveThread);//thread object creation
thread1.start();//starting of thread1
}
}
class RecieveThread implements Runnable
{
Socket soc=null;
BufferedReader recieve=null;
public RecieveThread(Socket soc)//constructor
{
this.soc=soc;
}
public void run()
{
try
{
recieve=new BufferedReader(new InputStreamReader(this.soc.getInputStream()));//meessage from client
String msgRecieved=null;
while((msgRecieved=recieve.readLine())!=null)
{
System.out.println("From Server: "+msgRecieved);//message recieved from client
}
}
//catch Exception
catch(IOException ex)
{
System.out.println(ex.getMessage());
}
}
}
class SendThread implements Runnable
{
Socket soc=null;
PrintWriter print=null;
BufferedReader input=null;
//SendThread Constructor
public SendThread(Socket soc)
{
this.soc=soc;
}
public void run()
{
try
{
if(soc.isConnected())
{
System.out.println("client connected to server "+soc.getInetAddress());
this.print=new PrintWriter(soc.getOutputStream(),true);
System.out.println("Start the chat");
while(true)
{
System.out.println("press EXIT to close");
input=new BufferedReader(new InputStreamReader(System.in));//send to server
String msgtoServerString=null;
msgtoServerString=input.readLine();//send message to server
this.print.println(msgtoServerString);
this.print.flush();//flush the buffer
if(msgtoServerString.equals("EXIT"))
break;//close socket if
}//end while
soc.close();//close the socket
}
}
//catch exception
catch(IOException e)
{
System.out.println(e.getMessage());
}
}//end run method
}//end class