Fspchatbot
Fspchatbot
package server1;
import java.io.IOException;
import java.net.BindException;
import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.lang.ClassNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.stage.Stage;
import javax.swing.JOptionPane;
class Introduction extends Thread {
int basechoice=0;
System.out.println("*********************************************");
Thread.sleep(500);
System.out.println("*********************************************");
Thread.sleep(500);
System.out.println("*********************************************");
Thread.sleep(500);
System.out.println("*********************************************");
Thread.sleep(500);
System.out.println("*********************************************");
Thread.sleep(500);
Thread.sleep(500);
System.out.println("*********************************************");
Thread.sleep(500);
System.out.println("*********************************************");
Thread.sleep(500);
basechoice = scan.nextInt();
if ( basechoice == 1 )
Thread.sleep(500);
System.out.println("*********************************************");
Thread.sleep(500);
System.out.println("*********************************************");
Thread.sleep(500);
class optionpane
{
}
int i =0 ;
while ( true )
socket = server.accept();
i++;
clients.add(clientobject);
pool.execute(clientobject);
catch(IOException i)
System.out.println(i);
//
// obj.base();
// Application.launch(args);
JOptionPane.showMessageDialog( null, " We are now Coonecting " , " CHAT BOT ",
JOptionPane.PLAIN_MESSAGE );
} CLIENT CODE :
package client1;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.io.*;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.*;
import java.util.Scanner;
import javax.swing.JOptionPane;
System.out.println("*********************************************");
Thread.sleep(500);
System.out.println("*********************************************");
Thread.sleep(500);
System.out.println("*********************************************");
Thread.sleep(500);
System.out.println("*********************************************");
Thread.sleep(500);
System.out.println("*********************************************");
Thread.sleep(500);
Thread.sleep(500);
System.out.println("*********************************************");
Thread.sleep(500);
System.out.println("*********************************************");
Thread.sleep(500);
do{
clientchoice=scan.nextInt();
if(clientchoice==1)
System.out.println("*********************************************");
System.out.println("*********************************************");
System.out.println("3. CONNECTION IS MAINTAINED AS LONG YOU DON'T TYPE \" Over \" ");
System.out.println("*********************************************");
System.out.println("*********************************************");
else if (clientchoice == 2 )
{
System.out.println("*********************************************");
System.out.println("*********************************************");
System.out.println("*********************************************");
System.out.println("*********************************************");
else
System.out.println("*********************************************");
System.out.println("*********************************************");
System.out.println("*********************************************");
System.out.println("*********************************************");
} while ( clientchoice != 2 );
class Client {
String Name ;
// initialize socket and input output streams
//pp
int a=0;
// establish a connection
try
catch(UnknownHostException u)
System.out.println(u);
catch(IOException i)
System.out.println(i);
while (!line.equals("Over"))
try
line = input.readLine();
out.writeUTF(line);
}
catch(IOException i)
System.out.println(i);
try
input.close();
out.close();
socket.close();
catch(IOException i)
System.out.println(i);
//obj2.base2();
}
CLIENTHANDLER CODE ( MULTIPLE CLIENT
CONNECTION ) :
/*
*/
package server1;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;
import java.util.ArrayList;
/**
*/
this.socket=c;
this.clients= clients;
// }
@Override
try{
while (!line.equalsIgnoreCase("over"))
try
line = in.readUTF();
System.out.println(line);
// outToAll(line.substring(1));
catch(IOException i)
System.out.println(i);
System.out.println("Closing connection");
//ok++;
// close connection
socket.close();
in.close();
catch (IOException e)
{
e.printStackTrace();
//
// {
//
//
// }
// }
//
Output :
It ends when you write Over
But I want to implement kay server ko show ho kay kon message kar
raha ha like client 1 ya client 2
As
Or secondly , server sey message sab client ko jay , I tried using this but
it fails !