我用Java Swing重写了一些旧的Client-Server应用程序。当我在服务器上发布消息时-客户端会收到它,但是我也需要在服务器归档中接收相同的消息。就我而言,服务器仅接收最后发布的消息,而不是全部。有任何想法吗?谢谢
服务器完整代码:
package chatapplication;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Date;
public class Server extends javax.swing.JFrame {
static ServerSocket ssckt;
static Socket sckt;
static DataInputStream dtinpt;
static DataOutputStream dtotpt;
public Server() {
initComponents();
}
private void btnsendActionPerformed(java.awt.event.ActionEvent evt) {
try {
Date date = new Date();
String msgout = "";
String msgin = "";
jTextAreaServ.setText("\n Archive : " + jTextField1.getText().trim() + " " + date);
msgout = jTextField1.getText().trim();
//msgout = jTextAreaServ.getText().trim();
dtotpt.writeUTF(msgout);
jTextField1.setText("");
} catch (Exception e) {
}
}
private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Server().setVisible(true);
}
});
答案 0 :(得分:0)
答案是:
private void btnsendActionPerformed(java.awt.event.ActionEvent evt) {
try {
Date date = new Date();
String msgout = "";
String msgin = "";
msgout = jTextField1.getText().trim();
jTextField1.setText("");
dtotpt.writeUTF(msgout);
jTextAreaServ.setText( jTextAreaServ.getText().trim()+ "\n Archive : " + msgout + " " + date);
} catch (Exception e) {
}
}