如题
以下是代码,为了实现server端和client端的通信,server端能成功运行。
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;public class MyClient {
    public static void main(String[] args) {
     new ClientFrame();
    }
}
class ClientFrame extends Frame implements ActionListener
{
Socket clientSocket;
    BufferedReader cIn;
PrintWriter cOut;
String s;
TextArea textArea;
Button myButton = new Button("发送");
public ClientFrame()
{
setTitle("客户端socket窗口");
setLayout(new BorderLayout());
this.addWindowListener(new WinAdptClient(this));
myButton.addActionListener(this);
textArea=new TextArea(20,50);
add("South",myButton);
add("Center",textArea);
setVisible(true);
setSize(300,200);
try{
clientSocket=new Socket("wxy123",8000);
cIn = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
cOut = new PrintWriter(clientSocket.getOutputStream());
s = cIn.readLine();
textArea.append(s+"\n");
}catch(Exception e){}
}
public void actionPerformed(ActionEvent e)
{
try{
cOut.print(textArea.getText());
cOut.flush();
}catch(Exception ex){}
}
}
class WinAdptClient extends WindowAdapter
{
ClientFrame m_Parent;
WinAdptClient(ClientFrame p)
{
m_Parent=p;
}
public void windowClosing(WindowEvent e)
{
try{
m_Parent.cOut.println("bye");
m_Parent.cOut.flush();
m_Parent.cIn.close();
m_Parent.cOut.close();
m_Parent.clientSocket.close();
m_Parent.dispose();
System.exit(0);
}catch(Exception ex){}
}
}
求高手帮忙啊。谢谢!!