Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Java NetBeans:Sending multiple Messages: Erroneous sym type: Soc

  1. Aug 2, 2016 #1
    Hi,

    I made a program to send a message from a Server to a client on the same machine in NetBeans on a Button click. I used the following code in the button handler:


    Code (Java):
    private void sendMsgButtonActionPerformed(java.awt.event.ActionEvent evt) {

      // TODO add your handling code here:

      try{

      ServerSocket sSocket=new ServerSocket(800);

      System.out.println("Server Started");

      Socket cSocket=sSocket.accept();


      PrintWriter writer=new PrintWriter(cSocket.getOutputStream());

      writer.println("Hello I am the Server");


      writer.flush();

      writer.close();


      Thread.currentThread().sleep(2000);

      cSocket.close();

      sSocket.close();

      }catch(SocketTimeoutException s)

      {

      System.out.println("Socket timed out!");

       break;

      }

      catch(IOException e) {

      e.printStackTrace();

      }


      }
    It worked but when i pressed the button again to send another message , i got following error:

    To handle this error, i created two methods: createConnection( ) & closeConnection( ) but now i am getting following error:

    My complete server code is:

    Code (Java):
    import java.io.IOException;
    import java.io.PrintWriter;
    import java.net.ServerSocket;
    import java.net.Socket;
    import java.net.SocketTimeoutException;
    /*
    * To change this license header, choose License Headers in Project Properties.
    * To change this template file, choose Tools | Templates
    * and open the template in the editor.
    */

    /**
    *
    * @author HP
    */

    public class Server2JFrame extends javax.swing.JFrame {
        /**
         * Creates new form Server2JFrame
         */

        ServerSocket sSocket;
        Sockect cSocket;
        PrintWriter writer;
     
        public void createConnection( ){
             try{
             sSocket=new ServerSocket(800);
             System.out.println("Server Started");
             cSocket=sSocket.accept();    
            Thread.currentThread().sleep(2000);
         
            }catch(SocketTimeoutException s)
             {
                System.out.println("Socket timed out!");
                break;
             }
            catch(IOException e) {
                e.printStackTrace();
            }
        }
        public static void closeConnection(){
            cSocket.close();
            sSocket.close();
        }
             
        public Server2JFrame() {
            createConnection( );
            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() {
            jPanel1 = new javax.swing.JPanel();
            sendMesgButton = new javax.swing.JButton();
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            sendMesgButton.setText("Send Multiple Message");
            sendMesgButton.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    sendMesgButtonActionPerformed(evt);
                }
            });
            javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
            jPanel1.setLayout(jPanel1Layout);
            jPanel1Layout.setHorizontalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addGap(65, 65, 65)
                    .addComponent(sendMesgButton)
                    .addContainerGap(82, Short.MAX_VALUE))
            );
            jPanel1Layout.setVerticalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                    .addContainerGap(42, Short.MAX_VALUE)
                    .addComponent(sendMesgButton)
                    .addGap(35, 35, 35))
            );
            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(87, 87, 87)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(25, Short.MAX_VALUE))
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(79, 79, 79)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(121, Short.MAX_VALUE))
            );
            pack();
        }// </editor-fold>                      
        private void sendMesgButtonActionPerformed(java.awt.event.ActionEvent evt) {                                            
            // TODO add your handling code here:
            writer=new PrintWriter(cSocket.getOutputStream());
            writer.println("Hello I am the Server");
            writer.flush();
            writer.close();
        }                                            
        /**
         * @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(Server2JFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (InstantiationException ex) {
                java.util.logging.Logger.getLogger(Server2JFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (IllegalAccessException ex) {
                java.util.logging.Logger.getLogger(Server2JFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (javax.swing.UnsupportedLookAndFeelException ex) {
                java.util.logging.Logger.getLogger(Server2JFrame.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 Server2JFrame().setVisible(true);
                }
            });
            closeConnection( );
        }
        // Variables declaration - do not modify                  
        private javax.swing.JPanel jPanel1;
        private javax.swing.JButton sendMesgButton;
        // End of variables declaration                
    }
     

    and the client code is:

    Code (Java):
    import java.net.*;
    import java.io.*;
    public class NewJFrame extends javax.swing.JFrame {
        /**
         * Creates new form NewJFrame
         */

        public NewJFrame() {
            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() {
            jPanel1 = new javax.swing.JPanel();
            recvMesgButton = new javax.swing.JButton();
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            recvMesgButton.setText("Received Client Message");
            recvMesgButton.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    recvMesgButtonActionPerformed(evt);
                }
            });
            javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
            jPanel1.setLayout(jPanel1Layout);
            jPanel1Layout.setHorizontalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                    .addContainerGap(37, Short.MAX_VALUE)
                    .addComponent(recvMesgButton)
                    .addGap(34, 34, 34))
            );
            jPanel1Layout.setVerticalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addGap(66, 66, 66)
                    .addComponent(recvMesgButton)
                    .addContainerGap(71, Short.MAX_VALUE))
            );
            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(104, 104, 104)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(87, Short.MAX_VALUE))
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(55, 55, 55)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(85, Short.MAX_VALUE))
            );
            pack();
        }// </editor-fold>                      
        private void recvMesgButtonActionPerformed(java.awt.event.ActionEvent evt) {                                            
            // TODO add your handling code here:
           try{
           Socket toServer=new Socket(InetAddress.getLocalHost(),800);
           BufferedReader bufr=new BufferedReader(new InputStreamReader(toServer.getInputStream()));
           System.out.println(bufr.readLine());
           bufr.close();
           toServer.close();
           }catch(IOException e){
               e.printStackTrace();
                break;
           }
        }                                            
        /**
         * @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(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (InstantiationException ex) {
                java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (IllegalAccessException ex) {
                java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (javax.swing.UnsupportedLookAndFeelException ex) {
                java.util.logging.Logger.getLogger(NewJFrame.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 NewJFrame().setVisible(true);
                }
            });
        }
        // Variables declaration - do not modify                  
        private javax.swing.JPanel jPanel1;
        private javax.swing.JButton recvMesgButton;
        // End of variables declaration                
    }
     
    Some body please guide me how to get around with this problem.

    Zulfi.
     
  2. jcsd
  3. Aug 2, 2016 #2

    jedishrfu

    Staff: Mentor

    The first thing I do is to check for examples:

    http://cs.lmu.edu/~ray/notes/javanetexamples/ [Broken]

    and then see if my code is missing something.

    It looks like your code isn't closing the socket or terminating correctly (ie maybe its still running the first version). Netbeans has an indicator at the bottom right that shows what processes are running. Sometimes though it gets confused and a process that you launched is running but it thinks it has ended.

    Basically you need to still clean up stuff when you get an exception. What happens is when the exception is thrown everything that would normally be executed is skipped until your program has caught the exception then it gets back on track.
     
    Last edited by a moderator: May 8, 2017
  4. Aug 2, 2016 #3

    Svein

    User Avatar
    Science Advisor

    It looks to me as if you are trying to start a server at port 800 every time you push the button. That is not allowed, and that is why you get the error messages. Try to check if the server is already started and do not create a new one if it is.
     
  5. Aug 3, 2016 #4
    Hi,
    I am now getting address already Bind. I have created separate methods for createConnection( ) & closeConnection( ). I have checked that i am not invoking these methods repeatedly. I am closing the conncections in the exception handling code.
    Code (Java):
    import java.io.IOException;
    import java.io.PrintWriter;
    import java.net.ServerSocket;
    import java.net.Socket;
    import java.net.SocketTimeoutException;

    /*
    * To change this license header, choose License Headers in Project Properties.
    * To change this template file, choose Tools | Templates
    * and open the template in the editor.
    */


    /**
    *
    * @author HP
    */

    public class Server2JFrame extends javax.swing.JFrame {

        /**
         * Creates new form Server2JFrame
         */

        static ServerSocket sSocket;
        static Socket cSocket;
        static PrintWriter writer;
       
        public static void createConnection( ){
             try{
             sSocket=new ServerSocket(800);
             System.out.println("Server Started");
             cSocket=sSocket.accept();    
            //Thread.currentThread().sleep(2000);
           
            }catch(SocketTimeoutException s)
             {
                System.out.println("Socket timed out!");
                closeConnection();
                break;
             }
            catch(IOException e) {
    //            closeConnection();
                e.printStackTrace();
            }
        }
        public static void closeConnection(){
            try{
            cSocket.close();
            sSocket.close();
            }catch(IOException e) {
                e.printStackTrace();
            }
        }
               
        public Server2JFrame() {
           
            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() {

            jPanel1 = new javax.swing.JPanel();
            sendMesgButton = new javax.swing.JButton();

            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

            sendMesgButton.setText("Send Multiple Message");
            sendMesgButton.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    sendMesgButtonActionPerformed(evt);
                }
            });

            javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
            jPanel1.setLayout(jPanel1Layout);
            jPanel1Layout.setHorizontalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addGap(65, 65, 65)
                    .addComponent(sendMesgButton)
                    .addContainerGap(82, Short.MAX_VALUE))
            );
            jPanel1Layout.setVerticalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                    .addContainerGap(42, Short.MAX_VALUE)
                    .addComponent(sendMesgButton)
                    .addGap(35, 35, 35))
            );

            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(87, 87, 87)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(25, Short.MAX_VALUE))
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(79, 79, 79)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(121, Short.MAX_VALUE))
            );

            pack();
        }// </editor-fold>                      

        private void sendMesgButtonActionPerformed(java.awt.event.ActionEvent evt) {                                              
            // TODO add your handling code here:
            writer=new PrintWriter(cSocket.getOutputStream());
            writer.println("Hello I am the Server");

            writer.flush();
            writer.close();
        }                                            

        /**
         * @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(Server2JFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (InstantiationException ex) {
                java.util.logging.Logger.getLogger(Server2JFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (IllegalAccessException ex) {
                java.util.logging.Logger.getLogger(Server2JFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (javax.swing.UnsupportedLookAndFeelException ex) {
                java.util.logging.Logger.getLogger(Server2JFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            }
            //</editor-fold>
            createConnection( );
            /* Create and display the form */
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new Server2JFrame().setVisible(true);
                }
            });
            closeConnection( );
        }

        // Variables declaration - do not modify                    
        private javax.swing.JPanel jPanel1;
        private javax.swing.JButton sendMesgButton;
        // End of variables declaration                  
    }
     
    & the errors are:
    Somebody please guide me.
    Zulfi.
     
  6. Aug 3, 2016 #5

    jedishrfu

    Staff: Mentor

    Did you look at the examples link I posted earlier? Surely there's something that will help you.

    You either have something running on your machine that is using port 800 or one your earlier runs is still running.

    If you reboot does the program still say that its in use already if o then some other process on your machine is using that port and depending on your OS you can check to see who is via the command. Here's the Linux one:

    http://askubuntu.com/questions/538208/how-to-check-opened-closed-port-on-my-computer
     
  7. Aug 4, 2016 #6

    Svein

    User Avatar
    Science Advisor

    I am no Java expert, but I do know something about networking. When tracing through the error messages it ends up in "Address already in use". As already commented:
    I shall only add that port numbers below 1024 are so-called "well-known ports" and should not be used for anything but the "well-known applications". From rfc 1700:

    The assigned ports use a small portion of the possible port numbers. For many years the assigned ports were in the range 0-255. Recently, the range for assigned ports managed by the IANA has been expanded to the range 0-1023.

    Port Assignments:

    Keyword Decimal Description References
    ------- ------- ----------- ----------
    .....
    mdbs_daemon 800/tcp
    mdbs_daemon 800/udp
     
  8. Aug 4, 2016 #7
    Hi,
    Thanks my friends for your guidance.
    <Did you look at the examples link I posted earlier? >
    I have tried to change my code according to the first example in the document. But now I m not getting the "Bind error" but its not showing the Button.
    It prints the message server started.
    I tried to use debugger but now run to Cursor option has grayed. So i cant use it.

    My code is:
    Code (Text):
    import java.io.IOException;
    import java.io.PrintWriter;
    import java.net.ServerSocket;
    import java.net.Socket;
    import java.net.SocketTimeoutException;

    /*
    * To change this license header, choose License Headers in Project Properties.
    * To change this template file, choose Tools | Templates
    * and open the template in the editor.
    */

    /**
    *
    * @author HP
    */
    public class Server2JFrame extends javax.swing.JFrame {

        /**
         * Creates new form Server2JFrame
         */
        static ServerSocket sSocket;
        static Socket cSocket;
        static PrintWriter writer;
       
        public static void createConnection( ){
             try{
             sSocket=new ServerSocket(9090);
             System.out.println("Server Started");
             cSocket=sSocket.accept();    
            //Thread.currentThread().sleep(2000);
           
            }catch(SocketTimeoutException s)
             {
                System.out.println("Socket timed out!");
                closeConnection();
               
             }
            catch(IOException e) {
    //            closeConnection();
                e.printStackTrace();
            }
        }
        public static void closeConnection(){
            try{
            cSocket.close();
            sSocket.close();
            }catch(IOException e) {
                e.printStackTrace();
            }
        }
               
        public Server2JFrame() {
           
            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() {

            jPanel1 = new javax.swing.JPanel();
            sendMesgButton = new javax.swing.JButton();

            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

            sendMesgButton.setText("Send Multiple Message");
            sendMesgButton.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    sendMesgButtonActionPerformed(evt);
                }
            });

            javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
            jPanel1.setLayout(jPanel1Layout);
            jPanel1Layout.setHorizontalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addGap(65, 65, 65)
                    .addComponent(sendMesgButton)
                    .addContainerGap(82, Short.MAX_VALUE))
            );
            jPanel1Layout.setVerticalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                    .addContainerGap(42, Short.MAX_VALUE)
                    .addComponent(sendMesgButton)
                    .addGap(35, 35, 35))
            );

            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(87, 87, 87)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(25, Short.MAX_VALUE))
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(79, 79, 79)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(121, Short.MAX_VALUE))
            );

            pack();
        }// </editor-fold>                      

        private void sendMesgButtonActionPerformed(java.awt.event.ActionEvent evt) {                                              
            // TODO add your handling code here:
            try{
            writer=new PrintWriter(cSocket.getOutputStream(),true);
            writer.println("Hello I am the Server");

            writer.flush();
            writer.close();
            }catch(IOException e) {
                e.printStackTrace();
                try {
                cSocket.close();
                }catch(IOException ee){
                   
                }
            }
           
        }                                            

        /**
         * @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(Server2JFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (InstantiationException ex) {
                java.util.logging.Logger.getLogger(Server2JFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (IllegalAccessException ex) {
                java.util.logging.Logger.getLogger(Server2JFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (javax.swing.UnsupportedLookAndFeelException ex) {
                java.util.logging.Logger.getLogger(Server2JFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            }
            //</editor-fold>
            createConnection( );
            /* Create and display the form */
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new Server2JFrame().setVisible(true);
                }
            });
            closeConnection( );
        }

        // Variables declaration - do not modify                    
        private javax.swing.JPanel jPanel1;
        private javax.swing.JButton sendMesgButton;
        // End of variables declaration                  
    }
     
    Some body please guide me why i am not seeing the button.

    Zulfi.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted



Similar Discussions: NetBeans:Sending multiple Messages: Erroneous sym type: Soc
  1. New to NetBeans (Replies: 2)

Loading...