Hi, I have two applications,one is for server and the other is for client.at first I run my server application .then I will run the client application.When you run the client application,one frame will be shown which get user name and password and if they were correct,the other frame will be shown.but when I click on the Sign In button ,nothing will happen.would you please help me? thanks.
Main class in Server application:
public static void main(String[] args) {
System.out.println("Server is starting...");
ServerSocket server = null;
try {
server = new ServerSocket(5000);
} catch (IOException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
System.out.println("Server is listening...");
while (true) {
try {
Socket socket = server.accept();
} catch (IOException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
System.out.println("Client Connected...");
}
}
client class which has socket in it:
private static InformationClass info = new InformationClass();
private static Socket c;
static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
/**
* @param args the command line arguments
*/
public static void runAClient() {
try {
c = new Socket("localhost", 5000);
} catch (UnknownHostException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
}
public static void clienT(){ try {
BufferedReader read = new BufferedReader(new InputStreamReader(c.getInputStream()));
BufferedWriter write = new BufferedWriter(new OutputStreamWriter(c.getOutputStream()));
while (true) {
String string = reader.readLine();
write.write(string, 0, string.length());
write.newLine();
write.flush();
System.out.println(read.readLine());
}
} catch (Exception e) {
System.err.println(e);
}
}
public static boolean connected() {
boolean bool = false;
if (c.isConnected()) {
info.setSituation("Connected");
bool = true;
} else {
info.setSituation("disconnected");
bool = false;
}
return bool;
}
the main frame in the client application that I should run it ,after when i run the server application:(a part of that which is for Sign In button)
private void submit() {
String id = idField.getText();
char[] pass1 = passField.getPassword();
String pass = new String(pass1);
if (id.equals("") || pass.equals("")) {
ErrorFrame frame = new ErrorFrame();
frame.setVisible(true);
} else {
boolean b = Manager.Test(id, pass);
if (b == true) {
Main.runAClient();
boolean boOl = Main.connected();
if(boOl==true){
this.setVisible(false);
ListFrame fRAme = new ListFrame(client);
fRAme.setVisible(true);
}
else{
JOptionPane.showConfirmDialog(this, "You couldn't connect successfully,please try again!","sign_In Problem",JOptionPane.ERROR_MESSAGE);
return;
}
} else {
JOptionPane.showConfirmDialog(this, "You have entered wrong datas,try it again");
return;
}
}
}
EDIT: I have edited my client class.