I am a novice with Java, and my class has been given an assignment:
Design a client/server application in which a client communicates directly with a server. The server will store product and customer information in two separate files. The client application will allow a user to request product and customer information from the server. The server will retrieve and send the requested information to the client. The information will be displayed by the client in a user-friendly manner. It is suggested that your application use Swing components to support a user-friendly interface.
I haven't built a client-server application before. I followed a youtube video tutorial (https://www.youtube.com/watch?v=vCDrGJWqR8w) to build the client-server application itself, but I'm not sure how to implement sending the information from the text files from the server to the client. I'm having trouble finding an answer online, I don't know if I'm just not asking it the right way or what.
I thought I could add if statements in the server file, so when the client side enters the corresponding word, it will run the code to send that specific file's text to the client.
If anyone could direct me to how I can accomplish this, I would greatly appreciate it. My Instructor has not responded to me, and our tutoring service is down for maintenance this weekend.
Edit: I found a tutorial on how to create the GUI (https://www.youtube.com/watch?v=h3i459_arng). I decided that it might be easier to write the GUI and then add the file reading capability.
I also found a website on how to read the text from my files (https://www.geeksforgeeks.org/different-ways-reading-text-file-java/)
Right now I can get the text from the files to write to the JTextArea in the Server chat window, but I need it to be sent to the JTextArea in the Client chat window. How do I do that?
ChatClient.java code
package clientserver2;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author Jade
*/
public class ChatClient extends javax.swing.JFrame {
/**
* Creates new form ChatClient
*/
public ChatClient() {
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() {
jScrollPane1 = new javax.swing.JScrollPane();
jTextAreaChat = new javax.swing.JTextArea();
jPanel1 = new javax.swing.JPanel();
jScrollPane2 = new javax.swing.JScrollPane();
jTextAreaMessage = new javax.swing.JTextArea();
jButtonSend = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Client");
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowOpened(java.awt.event.WindowEvent evt) {
formWindowOpened(evt);
}
});
getContentPane().setLayout(new java.awt.BorderLayout(10, 10));
jTextAreaChat.setColumns(20);
jTextAreaChat.setRows(5);
jScrollPane1.setViewportView(jTextAreaChat);
getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);
jPanel1.setLayout(new java.awt.BorderLayout(10, 10));
jTextAreaMessage.setColumns(20);
jTextAreaMessage.setRows(5);
jScrollPane2.setViewportView(jTextAreaMessage);
jPanel1.add(jScrollPane2, java.awt.BorderLayout.CENTER);
jButtonSend.setText("Send");
jButtonSend.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButtonSendActionPerformed(evt);
}
});
jPanel1.add(jButtonSend, java.awt.BorderLayout.LINE_END);
getContentPane().add(jPanel1, java.awt.BorderLayout.PAGE_END);
setBounds(0, 0, 407, 342);
}// </editor-fold>
private void jButtonSendActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String message = jTextAreaMessage.getText();
writer.println(message);
writer.flush();
jTextAreaChat.append("Client: " + message + "\n");
jTextAreaMessage.setText("");
}
private void formWindowOpened(java.awt.event.WindowEvent evt) {
try {
// TODO add your handling code here:
socket = new Socket("localhost", 4789);
scanner = new Scanner(socket.getInputStream());
writer = new PrintWriter(socket.getOutputStream());
Thread myThread = new Thread(new Runnable(){
@Override
public void run(){
jTextAreaChat.append("Welcome! Please enter a command." + "\n");
jTextAreaChat.append("Enter products to view list of products." + "\n");
jTextAreaChat.append("Enter customers to view list of customers." + "\n");
while(true){
//jTextAreaChat.append("Welcome! Please enter a command." + "\n");
//jTextAreaChat.append("Enter products to view list of products." + "\n");
//jTextAreaChat.append("Enter customers to view list of customers." + "\n");
String message = scanner.nextLine();
jTextAreaChat.append("Server: " + message + "\n");
}
}
});
myThread.start();
} catch (IOException ex) {
Logger.getLogger(ChatClient.class.getName()).log(Level.SEVERE, null, ex);
}
}
/**
* @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(ChatClient.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(ChatClient.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(ChatClient.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(ChatClient.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 ChatClient().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButtonSend;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JTextArea jTextAreaChat;
private javax.swing.JTextArea jTextAreaMessage;
// End of variables declaration
private Socket socket;
private Scanner scanner;
private PrintWriter writer;
}
ChatServer.java code
package clientserver2;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author Jade
*/
public class ChatServer extends javax.swing.JFrame {
/**
* Creates new form ChatClient
*/
public ChatServer() {
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() {
jScrollPane1 = new javax.swing.JScrollPane();
jTextAreaChat = new javax.swing.JTextArea();
jPanel1 = new javax.swing.JPanel();
jScrollPane2 = new javax.swing.JScrollPane();
jTextAreaMessage = new javax.swing.JTextArea();
jButtonSend = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Server");
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowOpened(java.awt.event.WindowEvent evt) {
formWindowOpened(evt);
}
});
getContentPane().setLayout(new java.awt.BorderLayout(10, 10));
jTextAreaChat.setColumns(20);
jTextAreaChat.setRows(5);
jTextAreaChat.setText("Waiting for Client...\n");
jScrollPane1.setViewportView(jTextAreaChat);
getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);
jPanel1.setLayout(new java.awt.BorderLayout(10, 10));
jTextAreaMessage.setColumns(20);
jTextAreaMessage.setRows(5);
jScrollPane2.setViewportView(jTextAreaMessage);
jPanel1.add(jScrollPane2, java.awt.BorderLayout.CENTER);
jButtonSend.setText("Send");
jButtonSend.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButtonSendActionPerformed(evt);
}
});
jPanel1.add(jButtonSend, java.awt.BorderLayout.LINE_END);
getContentPane().add(jPanel1, java.awt.BorderLayout.PAGE_END);
setBounds(0, 0, 407, 342);
}// </editor-fold>
private void jButtonSendActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String message = jTextAreaMessage.getText();
writer.println(message);
jTextAreaChat.append("Server: " + message + "\n");
jTextAreaMessage.setText("");
}
private void formWindowOpened(java.awt.event.WindowEvent evt) {
try {
// TODO add your handling code here:
serverSocket = new ServerSocket(4789);
socket = serverSocket.accept();
jTextAreaChat.append("Client found." + "\n");
scanner = new Scanner(socket.getInputStream());
writer = new PrintWriter(socket.getOutputStream(), true);
Thread myThread = new Thread(new Runnable() {
@Override
public void run(){
while(true){
String message = scanner.nextLine();
jTextAreaChat.append("Client: " + message + "\n");
if (message.equalsIgnoreCase("products"))
{
try {
File file = new File("C:\\Users\\jades\\Desktop\\Java\\ClientServer2\\src\\clientserver2\\Products.txt");
Scanner sc = new Scanner(file);
while (sc.hasNextLine()){
jTextAreaChat.append(sc.nextLine() + "\n");
}
} catch (FileNotFoundException ex) {
Logger.getLogger(ChatServer.class.getName()).log(Level.SEVERE, null, ex);
}
}
if (message.equalsIgnoreCase("customers"))
{
try {
File file = new File("C:\\Users\\jades\\Desktop\\Java\\ClientServer2\\src\\clientserver2\\Customers.txt");
Scanner sc = new Scanner(file);
while (sc.hasNextLine()){
jTextAreaChat.append(sc.nextLine() + "\n");
}
} catch (FileNotFoundException ex) {
Logger.getLogger(ChatServer.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
});
myThread.start();
} catch (IOException ex) {
Logger.getLogger(ChatServer.class.getName()).log(Level.SEVERE, null, ex);
}
}
/**
* @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(ChatServer.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(ChatServer.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(ChatServer.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(ChatServer.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new ChatServer().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButtonSend;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JTextArea jTextAreaChat;
private javax.swing.JTextArea jTextAreaMessage;
// End of variables declaration
private ServerSocket serverSocket;
private Socket socket;
private Scanner scanner;
private PrintWriter writer;
}
just in case anyone was wondering, I figured this out. I had gotten the GUI added, and found the code to read from a txt file, but I was stuck because the text from the file was being added to the Server's GUI, and I needed it added to the Client's GUI.
I needed to use my PrintWriter object writer to send the text to my Client.
Here is my updated code:
ChatClient.java file
package clientserver2;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;
public class ChatClient extends javax.swing.JFrame {
public ChatClient() {
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() {
jScrollPane1 = new javax.swing.JScrollPane();
jTextAreaChat = new javax.swing.JTextArea();
jPanel1 = new javax.swing.JPanel();
jScrollPane2 = new javax.swing.JScrollPane();
jTextAreaMessage = new javax.swing.JTextArea();
jButtonSend = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Client");
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowOpened(java.awt.event.WindowEvent evt) {
formWindowOpened(evt);
}
});
getContentPane().setLayout(new java.awt.BorderLayout(10, 10));
jTextAreaChat.setColumns(20);
jTextAreaChat.setRows(5);
jScrollPane1.setViewportView(jTextAreaChat);
getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);
jPanel1.setLayout(new java.awt.BorderLayout(10, 10));
jTextAreaMessage.setColumns(20);
jTextAreaMessage.setRows(5);
jScrollPane2.setViewportView(jTextAreaMessage);
jPanel1.add(jScrollPane2, java.awt.BorderLayout.CENTER);
jButtonSend.setText("Send");
jButtonSend.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButtonSendActionPerformed(evt);
}
});
jPanel1.add(jButtonSend, java.awt.BorderLayout.LINE_END);
getContentPane().add(jPanel1, java.awt.BorderLayout.PAGE_END);
setBounds(0, 0, 407, 342);
}// </editor-fold>
private void jButtonSendActionPerformed(java.awt.event.ActionEvent evt) {
String message = jTextAreaMessage.getText();
writer.println(message);
writer.flush();
jTextAreaChat.append("Client: " + message + "\n");
jTextAreaMessage.setText("");
}
private void formWindowOpened(java.awt.event.WindowEvent evt) {
try {
socket = new Socket("localhost", 4789);
scanner = new Scanner(socket.getInputStream());
writer = new PrintWriter(socket.getOutputStream());
Thread myThread = new Thread(new Runnable(){
@Override
public void run(){
jTextAreaChat.append("Welcome! Please enter a command." + "\n");
jTextAreaChat.append("Enter products to view list of products." + "\n");
jTextAreaChat.append("Enter customers to view list of customers." + "\n");
while(true){
String message = scanner.nextLine();
jTextAreaChat.append(message + "\n");
}
}
});
myThread.start();
} catch (IOException ex) {
Logger.getLogger(ChatClient.class.getName()).log(Level.SEVERE, null, ex);
}
}
/**
* @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(ChatClient.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(ChatClient.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(ChatClient.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(ChatClient.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 ChatClient().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButtonSend;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JTextArea jTextAreaChat;
private javax.swing.JTextArea jTextAreaMessage;
// End of variables declaration
private Socket socket;
private Scanner scanner;
private PrintWriter writer;
}
ChatServer.java file
package clientserver2;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;
public class ChatServer extends javax.swing.JFrame {
public ChatServer() {
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() {
jScrollPane1 = new javax.swing.JScrollPane();
jTextAreaChat = new javax.swing.JTextArea();
jPanel1 = new javax.swing.JPanel();
jScrollPane2 = new javax.swing.JScrollPane();
jTextAreaMessage = new javax.swing.JTextArea();
jButtonSend = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Server");
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowOpened(java.awt.event.WindowEvent evt) {
formWindowOpened(evt);
}
});
getContentPane().setLayout(new java.awt.BorderLayout(10, 10));
jTextAreaChat.setColumns(20);
jTextAreaChat.setRows(5);
jTextAreaChat.setText("Waiting for Client...\n");
jScrollPane1.setViewportView(jTextAreaChat);
getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);
jPanel1.setLayout(new java.awt.BorderLayout(10, 10));
jTextAreaMessage.setColumns(20);
jTextAreaMessage.setRows(5);
jScrollPane2.setViewportView(jTextAreaMessage);
jPanel1.add(jScrollPane2, java.awt.BorderLayout.CENTER);
jButtonSend.setText("Send");
jButtonSend.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButtonSendActionPerformed(evt);
}
});
jPanel1.add(jButtonSend, java.awt.BorderLayout.LINE_END);
getContentPane().add(jPanel1, java.awt.BorderLayout.PAGE_END);
setBounds(0, 0, 407, 342);
}// </editor-fold>
private void jButtonSendActionPerformed(java.awt.event.ActionEvent evt) {
String message = jTextAreaMessage.getText();
writer.println(message);
jTextAreaChat.append("Server: " + message + "\n");
jTextAreaMessage.setText("");
}
private void formWindowOpened(java.awt.event.WindowEvent evt) {
try {
// TODO add your handling code here:
serverSocket = new ServerSocket(4789);
socket = serverSocket.accept();
jTextAreaChat.append("Client found." + "\n");
scanner = new Scanner(socket.getInputStream());
writer = new PrintWriter(socket.getOutputStream(), true);
Thread myThread = new Thread(new Runnable() {
@Override
public void run(){
while(true){
String message = scanner.nextLine();
jTextAreaChat.append("Client: " + message + "\n");
if (message.equalsIgnoreCase("products"))
{
try {
File file = new File("C:\\Users\\jades\\Desktop\\Java\\ClientServer2\\src\\clientserver2\\Products.txt");
Scanner sc = new Scanner(file);
while (sc.hasNextLine()){
writer.println(sc.nextLine());
writer.flush();
}
} catch (FileNotFoundException ex) {
Logger.getLogger(ChatServer.class.getName()).log(Level.SEVERE, null, ex);
}
}
if (message.equalsIgnoreCase("customers"))
{
try {
File file = new File("C:\\Users\\jades\\Desktop\\Java\\ClientServer2\\src\\clientserver2\\Customers.txt");
Scanner sc = new Scanner(file);
while (sc.hasNextLine()){
writer.println(sc.nextLine());
writer.flush();
}
} catch (FileNotFoundException ex) {
Logger.getLogger(ChatServer.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
});
myThread.start();
} catch (IOException ex) {
Logger.getLogger(ChatServer.class.getName()).log(Level.SEVERE, null, ex);
}
}
/**
* @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(ChatServer.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(ChatServer.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(ChatServer.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(ChatServer.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new ChatServer().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButtonSend;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JTextArea jTextAreaChat;
private javax.swing.JTextArea jTextAreaMessage;
// End of variables declaration
private ServerSocket serverSocket;
private Socket socket;
private Scanner scanner;
private PrintWriter writer;
}