title: How can i send multiple information from a client application to a server?
body: <p>I'm new in regards to sockets and I would like to know how can i take what is written in several textfields from the client application and put that data into labels located in the Server application depending on the textfield that they come from.</p>
  <p>So far I made the connection between the client and the server and when you press the button in the client class you can send the string from the textfield and succesfully write that in the label located in the server class.</p>
  <p>Here I have the Client class</p>
  <pre><code>import javax.swing.*;
  import java.awt.*;
  import java.awt.event.*;
  import java.net.*;
  import java.io.*;
  
  class Client extends JFrame implements ActionListener{
      JTextField field1;
      JTextField field2;
      JPanel panel;
      JButton btnStart;
      JLabel lblText;
  
      public Client(){
          panel = new JPanel();
          panel.setLayout(null);
  
          lblText=new JLabel(&quot;CLIENT&quot;);
          lblText.setBounds(75,0,150,30);
          field1=new JTextField(20);
          field1.setBounds(10,40,225,30);
          field2=new JTextField(20);
          field2.setBounds(10,80,225,30);
          btnStart=new JButton(&quot;Send&quot;);
          btnStart.setBounds(75,100,75,30);
          btnStart.addActionListener(this);
  
          panel.add(btnStart);
          panel.add(field1);
          panel.add(field2);
          panel.add(lblText);
  
          this.add(panel);
          this.setBounds(600,300,275,500);
          this.setVisible(true);
          this.setDefaultCloseOperation(EXIT_ON_CLOSE);
      }
      public void actionPerformed(ActionEvent event){
          if(event.getSource() == this.btnStart){
              try {
                  Socket socket = new Socket(&quot;192.168.1.90&quot;,9000);
                  DataOutputStream out = new DataOutputStream(socket.getOutputStream());
                  out.writeUTF(field1.getText());
                  out.close();
                  field1.setText(&quot;&quot;);/*
                  DataOutputStream out2 = new DataOutputStream(socket.getOutputStream());
                  out2.writeUTF(field2.getText());
                  out2.close();
                  */
              }catch (Exception e) {
                  System.out.println(&quot;Connection failed&quot;);
              }
  
          }
      }
  }
  </code></pre>
  <p>Server class</p>
  <pre><code>import javax.swing.*;
  import java.awt.*;
  import java.net.*;
  import java.io.*;
  
  class Server extends JFrame implements Runnable{
    JLabel lblUsername;
    JLabel lblNss;
    JPanel panel;
    Thread thread1;
  
    public Server(){
      panel= new JPanel();
          panel.setLayout(null);
          lblUsername = new JLabel(&quot;&quot;);
      lblUsername.setBounds(0,0,150,30);
      lblNss = new JLabel(&quot;&quot;);
      lblNss.setBounds(0,40,150,30);
      panel.add(lblUsername);panel.add(lblNss);
  
      thread1 = new Thread(this);
      thread1.start();
  
  
          this.add(panel);
      this.setBounds(1200,300,280,350);
          this.setVisible(true);
      this.setDefaultCloseOperation(EXIT_ON_CLOSE);
      }
    public void run(){
      try {
        ServerSocket server = new ServerSocket(9000); 
        while(true){
          Socket socket = server.accept(); 
          DataInputStream in = new DataInputStream(socket.getInputStream());
          String text_message = in.readUTF();
          lblUsername.setText(text_message);
          //lblNss.setText();
          socket.close();
        }
      }catch (Exception e) {
        e.printStackTrace();
      }
  
    }
  }
  </code></pre>