Results 1 to 20 of 41
Thread: USerName, Password From Cliet
-
USerName, Password From Cliet
Good to meet you all!
In my program, The ServerSocket want's to receive the UserName, Password From Client when Client Login,
Any one can help me,
i try to use ServerSocket / Socket
i don't kow how to set the stream to ServerSocket
else
can you please show me the model coding for "Get input from user on Socket"
Thank you..,
- 04-27-2012, 02:15 PM #2
Re: USerName, Password From Cliet
Get input from user
With the console you can use the Scanner class to get input from a user. Or you could use a JOptionPane that would put up a window for the input.If you don't understand my response, don't ignore it, ask a question.
-
Re: USerName, Password From Cliet
I Thanking you for your response sir,
i am using JTextBox and JPassWord field in swing sir..,
- 04-27-2012, 02:33 PM #4
Re: USerName, Password From Cliet
Then what does your code do after it gets the user's input?
If you don't understand my response, don't ignore it, ask a question.
-
problem with Database to access Server/ServerSocket
Good To Meet you All!
Sir In my server
This is the JButton action for start server
Java Code:private void strsrvActionPerformed(java.awt.event.ActionEvent evt) { getClint(); }
Java Code:public void getClint() { try { ServerSocket ss=new ServerSocket(1030); try { JOptionPane.showMessageDialog(null,"Server is runing"); while(true) { Socket s=ss.accept(); Service a=new Service(s); a.start(); } } catch(Exception e) { System.out.println(e); } } catch(IOException ex) { Logger.getLogger(MainF.class.getName()).log(Level.SEVERE, null,ex); } }
Java Code:public class Service extends Thread { public Socket s; public Service(Socket t) { s=t; } public void run() { try { BufferedReader input = new BufferedReader(new InputStreamReader(s.getInputStream())); PrintWriter output = new PrintWriter(new OutputStreamWriter(s.getOutputStream())); String userName = input.readLine(); String password = input.readLine(); String getd=input.readLine(); try { Class.forName("com.mysql.jdbc.Driver"); Connection conn = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/payslip", "root", "root"); PreparedStatement ps = conn.prepareStatement("select * from employeenew where un='"+userName+"' and pw='"+password+"'"); ps.execute(); while(true) { PreparedStatement ps1 = conn.prepareStatement("insert into attents (un='"+userName+"',pw='"+password+"',intim='"+getd+"')"); output.println("You Have LogIn" + userName); ps1.executeUpdate(); conn.close(); } } catch (Exception e) { JOptionPane.showMessageDialog(rootPane,"LoginFailed"); } output.close(); input.close(); s.close(); } catch(Exception e) { System.out.println(e); } } }
The client code is
Java Code:/* * To change this template, choose Tools | Templates * and open the template in the editor. */ /* * Client.java * * Created on Apr 28, 2012, 10:58:31 AM */ import java.io.*; import java.net.*; import java.util.Calendar; import java.util.Date; import javax.swing.JOptionPane; /** * * @author e-soft */ public class Client extends javax.swing.JFrame { Socket s; /** Creates new form Client */ public Client() { initComponents(); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { un = new javax.swing.JTextField(); pw = new javax.swing.JTextField(); lin = new javax.swing.JButton(); lo = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); lin.setText("LogIn"); lin.addMouseListener(new java.awt.event.MouseAdapter() { public void mousePressed(java.awt.event.MouseEvent evt) { linMousePressed(evt); } }); lin.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { linActionPerformed(evt); } }); lo.setText("LogOut"); lo.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { loActionPerformed(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(pw, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(un, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(22, 22, 22)) .addGroup(layout.createSequentialGroup() .addComponent(lin) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 94, Short.MAX_VALUE) .addComponent(lo) .addGap(79, 79, 79)))) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(37, 37, 37) .addComponent(un, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addComponent(pw, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(lin) .addComponent(lo)) .addContainerGap(24, Short.MAX_VALUE)) ); pack(); }// </editor-fold> private void linActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: try { Socket s=new Socket("192.168.1.8",1030); PrintWriter output = new PrintWriter(new OutputStreamWriter(s.getOutputStream())); String userName =un.getText(); output.println(userName); String password =pw.getText(); output.println(password); Date dt=Calendar.getInstance().getTime(); Date timzn=(dt); output.println(timzn); output.flush(); BufferedReader input = new BufferedReader(new InputStreamReader(s.getInputStream())); String response = input.readLine(); JOptionPane.showMessageDialog(rootPane, response); output.close(); input.close(); s.close(); lo.setEnabled(true); lin.setEnabled(false); } catch (Exception e) { JOptionPane.showMessageDialog(rootPane, "Server Is Not In Conection"); } } private void loActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: lin.setEnabled(true); lo.setEnabled(false); } private void linMousePressed(java.awt.event.MouseEvent evt) { // TODO add your handling code here: } /** * @param args the command line arguments */ public static void main(String args[]) { /* Set the Nimbus look and feel */ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(Client.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(Client.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(Client.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(Client.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new Client().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JButton lin; private javax.swing.JButton lo; private javax.swing.JTextField pw; private javax.swing.JTextField un; // End of variables declaration }
My problem is
the server can use the username and password as static declaration only
But
if i connect to database it showing error while before access the database,
(even it not access the database try Block)
and the error message also unable to read, it showing transparent-able or black screen sir..,
(I Don't know how to properly use the database with server)
Anyone can help me please..,
Thank you..,
- 04-28-2012, 04:57 PM #6
Re: USerName, Password From Cliet
the error message also unable to read
You need to add a call to the printStacktTrace() method in the catch blocks so that the full text of the error message is shown.
To copy the contents of the command prompt window:
Click on Icon in upper left corner
Select Edit
Select 'Select All' - The selection will show
Click in upper left again
Select Edit and click 'Copy'
Paste here.If you don't understand my response, don't ignore it, ask a question.
-
- 04-28-2012, 05:30 PM #8
Re: USerName, Password From Cliet
it showing error
Did you add the call to printStackTrace to all the catch blocks?If you don't understand my response, don't ignore it, ask a question.
-
Re: USerName, Password From Cliet
Thank you sir!
i made a small changes in my code sir,
it allow the user to access the server.
the problem is, i fail to close the proper braces sir,
i very thank you sir..,
- 04-28-2012, 05:55 PM #10
Re: USerName, Password From Cliet
Was it the stupid IDE that did not give you a compiler error message?
If you don't understand my response, don't ignore it, ask a question.
-
Re: USerName, Password From Cliet
sir that is not a IDE problem sir,
I made that Stupid thing,
By mistakenly i mark that braces as lines of //,
when it ask me "run with error " i select "ok" sir ,
it is my mistake only.
sorry for that sir..,
- 04-28-2012, 06:06 PM #12
Re: USerName, Password From Cliet
Cross posted at problem with Database to access Server/ServerSocket | DaniWeb
If you don't understand my response, don't ignore it, ask a question.
-
Re: USerName, Password From Cliet
Hi Nice to meet you!
In my part of the application i wants to start the server for receive the user log in info ,
(username, password & log in time)
All parts in my application is working well but if i start the server my total application is Become Black and Unable to do any action in that,
If i run individually it is working well sir..,
For the past 8hrs i try to find solution but it is making problems only..,
The server side only making problem
code for server for multiple client
Java Code:try { ServerSocket ss=new ServerSocket(1099); try { JOptionPane.showMessageDialog(null,"Server is runing"); System.out.println("server started"); while(true) { Socket s=ss.accept(); Service a=new Service(s); a.start(); } } catch(Exception e) { System.out.println(e); } } catch(IOException ex) { Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null,ex); }
Java Code:package test; import tcp.*; import java.io.*; import java.net.*; import java.sql.*; /* * To change this template, choose Tools | Templates * and open the template in the editor. */ /** * * @author */ public class Service extends Thread { private Socket s=null; private PrintStream out= null; private DataInputStream in=null; BufferedReader input=null; public Service(Socket t)throws Exception { s=t; out=new PrintStream(s.getOutputStream()); in=new DataInputStream(s.getInputStream()); } public void run() { try { BufferedReader input = new BufferedReader(new InputStreamReader(s.getInputStream())); PrintWriter output = new PrintWriter(s.getOutputStream(),true); while(true) { String userName = input.readLine(); String password = input.readLine(); String getd=input.readLine(); try { Class.forName("com.mysql.jdbc.Driver"); Connection conn = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/payslip", "root", "root"); PreparedStatement ps = conn.prepareStatement("select * from employeenew where un='"+userName+"' and pw='"+password+"'"); ps.execute(); while(true) { PreparedStatement ps1 = conn.prepareStatement("insert into attents (un='"+userName+"',pw='"+password+"',intim='"+getd+"')"); output.println("You Have LogIn" + userName); ps1.executeUpdate(); conn.close(); } } catch (Exception e) { e.printStackTrace(); } } } catch(Exception e) { e.printStackTrace(); } } }
- 05-01-2012, 01:37 PM #14
Re: USerName, Password From Cliet
but if i start the server my total application is Become Black
What does "become black" mean?If you don't understand my response, don't ignore it, ask a question.
-
Re: USerName, Password From Cliet
Thank you sir!
i will explain to you,
In my pay slip program i have Modules of (Workers info, Pay slip,Leave info and Attendance)
In that attendance panel i have option to start & stop server (if any worker at morning logged in with client application (username, password & System time) )
(Sorry for attach as picture sir)
it will be sent to my Payslip application
the application is working well. (Before start the server)
But!
if i start the server it will become
like this sir..,
Thank you sir..,
- 05-01-2012, 02:11 PM #16
Re: USerName, Password From Cliet
if i start the server it will become
Try executing the code in a command prompt and not in an IDE. So the IDE can NOT affect what the code is doing.
Add some println statements to the servers code so you can see where it has executed and where the execution has stopped waiting for input or whatever.If you don't understand my response, don't ignore it, ask a question.
-
Re: USerName, Password From Cliet
Thank you sir!
i fallow your guide now..,
-
Re: USerName, Password From Cliet
"it" meant the Payslip application sir..,
- 05-01-2012, 02:18 PM #19
Re: USerName, Password From Cliet
are there any error messages on the console?
Can you post a small simple program for the server and client that will compile. execute and show the problem? I don't see complete code here for a server.Last edited by Norm; 05-01-2012 at 02:24 PM. Reason: Request code for server
If you don't understand my response, don't ignore it, ask a question.
-
Re: USerName, Password From Cliet
ok sir!
Java Code:/* * To change this template, choose Tools | Templates * and open the template in the editor. */ /* * serverFm.java * * Created on May 1, 2012, 10:25:17 AM */ /** * * @author */ import java.net.*; import java.io.*; import java.sql.*; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.JOptionPane; public class serverFm extends javax.swing.JFrame { ServerSocket server = null; Socket client = null; BufferedReader in = null; PrintWriter out = null; String UName; String Passw; String getd; /** Creates new form serverFm */ public serverFm() { initComponents(); UName = ""; Passw=""; getd=""; } public void service() { try { server = new ServerSocket(1099); client = server.accept(); } catch(Exception e) { JOptionPane.showMessageDialog(rootPane,"Accept failed :"); } try { in = new BufferedReader(new InputStreamReader(client.getInputStream())); out = new PrintWriter(client.getOutputStream(), true); } catch (IOException e) { JOptionPane.showMessageDialog(rootPane,"Read failed"); System.exit(-1); } if(true) { try { UName = in.readLine(); Passw=in.readLine(); getd=in.readLine(); //Send data back to client //out.println(Passw); try { Class.forName("com.mysql.jdbc.Driver"); Connection conn = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/payslip", "root", "root"); PreparedStatement ps = conn.prepareStatement("select * from employeenew where un='"+UName+"' and pw='"+Passw+"'"); ps.execute(); if(true) { try { PreparedStatement ps1 = conn.prepareStatement("INSERT INTO payslip.attents (un, pw, intim) VALUES(?,?,?)"); ps1.setString(1, UName); ps1.setString(2, Passw); ps1.setString(3, getd); JOptionPane.showMessageDialog(null,"You Have LogIn with " + UName); ps1.executeUpdate(); JOptionPane.showMessageDialog(rootPane,"Login successfully"); } catch(Exception e) { JOptionPane.showMessageDialog(rootPane, "Check Your UserName & PassWord Please..,"); } } } catch (Exception e) { e.printStackTrace(); } out.println(UName); } catch (IOException ex) { Logger.getLogger(serverFm.class.getName()).log(Level.SEVERE, null, ex); } } } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { hai = new javax.swing.JTextField(); pwws = new javax.swing.JPasswordField(); jButton1 = new javax.swing.JButton(); dttte = new javax.swing.JLabel(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosed(java.awt.event.WindowEvent evt) { formWindowClosed(evt); } }); jButton1.setText("Get"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(147, 147, 147) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) .addComponent(pwws, javax.swing.GroupLayout.Alignment.LEADING) .addComponent(hai, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 157, Short.MAX_VALUE)) .addContainerGap(96, Short.MAX_VALUE)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap(168, Short.MAX_VALUE) .addComponent(jButton1) .addGap(183, 183, 183)) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(dttte, javax.swing.GroupLayout.PREFERRED_SIZE, 152, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(238, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(dttte, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(hai, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addComponent(pwws, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(26, 26, 26) .addComponent(jButton1) .addContainerGap(19, Short.MAX_VALUE)) ); pack(); }// </editor-fold> private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: } private void formWindowClosed(java.awt.event.WindowEvent evt) { // TODO add your handling code here: try { in.close(); out.close(); server.close(); } catch (IOException e) { JOptionPane.showMessageDialog(rootPane,"Could not close."); System.exit(-1); } } /** * @param args the command line arguments */ public static void main(String args[]) { /* Set the Nimbus look and feel */ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(serverFm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(serverFm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(serverFm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(serverFm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new serverFm().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JLabel dttte; private javax.swing.JTextField hai; private javax.swing.JButton jButton1; private javax.swing.JPasswordField pwws; // End of variables declaration }
Java Code:/* * To change this template, choose Tools | Templates * and open the template in the editor. */ /** * * @author */ public class ServerMain { public static void main(String[] args) { serverFm s = new serverFm(); s.setVisible(true); s.service(); } }
Similar Threads
-
Username And Password
By razmyasdfg in forum JDBCReplies: 9Last Post: 05-18-2011, 03:59 PM -
New to GUI. Logging in with Password and username
By slitka in forum New To JavaReplies: 3Last Post: 04-12-2011, 12:39 AM -
Encrypt Password and Username
By hardcorebadger in forum New To JavaReplies: 5Last Post: 01-26-2011, 04:47 PM -
how to link url with username and password
By gb.rashu in forum JavaServer Pages (JSP) and JSTLReplies: 13Last Post: 08-12-2010, 04:12 PM -
JTextFields with username & password.
By Eric in forum AWT / SwingReplies: 2Last Post: 07-02-2007, 12:41 AM
Bookmarks