import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class MulServer {
static boolean runnig;
static Thread horch;
static JButton button1;
static JLabel label1;
public static void main(String args[]) throws IOException {
runnig = false;
horch = new Thread(new Runnable() {
public void run() {
try {
while (runnig) {
ServerSocket server = new ServerSocket(3145);
Socket client = server.accept();
InputStream in = client.getInputStream();
OutputStream out = client.getOutputStream();
int start = in.read();
int end = in.read();
int result = start * end;
out.write(result);
client.close();
}
} catch (IOException e) {
System.err.println("Problem");
}
}
});
JFrame f = new JFrame("Datenserver");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container con = f.getContentPane();
con.setLayout(new GridLayout(0, 1, 5, 5));
label1 = new JLabel("Noch nicht verbunden", JLabel.CENTER);
con.add(label1);
button1 = new JButton("Verbindung herstellen");
con.add(button1);
button1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (runnig) {
runnig = false;
label1.setText("Verbindung abgebrochen");
button1.setText("Verbindung herstellen");
} else {
runnig = true;
horch.start();
label1.setText("Verbunden");
button1.setText("Verbindung abbrechen");
}
}
});
f.setVisible(true);
}
}