客户端收不到服务器端的信息.(两个用户)
哪位大哥有类似的例子.给小弟一份看呀.huoyan190@sina.com QQ:573057075
服务器端:TcpServers .java
====================================================================
import java.net.*;
import java.io.*;
import java.awt.*;
import java.awt.Toolkit;
import javax.swing.*;
import javax.swing.Box;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class TcpServers extends JFrame implements ActionListener
{
JFrame frame;
JPanel contentpane,panel2;
JTextArea textarea;
JScrollPane panel3;
JButton allowLink;
JButton send;
JButton button;
JLabel message;
JLabel kehu;
JTextField textField;
JComboBox box1;
ServerSocket server;
Socket connection;
InputStream is;
OutputStream os;
BufferedReader br;
PrintWriter pw;
String client;
InetAddress client1,client2;
int port1,port2;
TcpServers()
{
frame=new JFrame( "服务器端 ");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setResizable(false);
frame.setSize(450,300);
contentpane=new JPanel();
panel2=new JPanel();
textarea=new JTextArea(15,10);
panel3=new JScrollPane(textarea);
allowLink=new JButton( "接受连接 ");
send=new JButton( "发送 ");
send.addActionListener(this);
textField=new JTextField(20);
box1=new JComboBox();
message=new JLabel( "消息 : ");
kehu=new JLabel( "客户端 : ");
Toolkit kit = Toolkit.getDefaultToolkit();
Image image = kit.getImage( "Ghosthuo.jpg ");
frame.setIconImage(image);
Box hbox1 = Box.createHorizontalBox();
hbox1.add(allowLink);
allowLink.addActionListener(this);
// 添加一个20像素的支柱
hbox1.add(Box.createHorizontalStrut(20));
hbox1.add(message);
hbox1.add(Box.createHorizontalStrut(20));
hbox1.add(textField);
Box hbox2 = Box.createHorizontalBox();
hbox2.add(Box.createHorizontalStrut(105));
hbox2.add(kehu);
// 添加一个20像素的支柱
hbox2.add(Box.createHorizontalStrut(8));
hbox2.add(box1);
hbox2.add(Box.createHorizontalStrut(20));
hbox2.add(send);
Box vbox = Box.createVerticalBox();
vbox.add(hbox1);
vbox.add(hbox2);
frame.setContentPane(contentpane);
contentpane.setLayout(new BorderLayout());
contentpane.add(vbox,BorderLayout.NORTH);
contentpane.add(panel3,BorderLayout.CENTER);
frame.setSize(450,300);
frame.setVisible(true);
frame.pack();
serverStart();