不会连接运行客户服务器连接,高手帮我!!!!!
客户端:
package yan1;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
class yan3 extends Object implements Serializable{
String cusname;
String cuspas;
}
public class Yan2 extends JApplet{
JPanel panel;
JLabel label1;
JLabel label2;
JTextField text1;
JPasswordField pas;
JButton button1;
public Yan2(){
panel=new JPanel();
FlowLayout ly=new FlowLayout(FlowLayout.RIGHT,5,5);
panel.setLayout(ly);
getContentPane().add(panel);
label1=new JLabel( "custom name: ");
label2=new JLabel( "password: ");
text1=new JTextField(5);
pas=new JPasswordField(16);
button1=new JButton( "logn ");
panel.add(label1);
panel.add(text1);
panel.add(label2);
panel.add(pas);
panel.add(button1);
}
public void init(){
new Yan2();
}
}
服务端:
package yan1;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
class yan3 extends Object implements Serializable{
String cusname;
String cuspas;
}
public class Yan2 extends JApplet{
public void init()
{new server();
LoginAction la=new LoginAction() ;
button1.addActionListener(la);
}
class LoginAction implements ActionListener
{void fail(String message,Exception e)
{getAppletContext().showStatus(message+ ". "+e);
}
public void actionPerformed(ActionEvent evt) {
Object obj=evt.getSource();
if(obj==button1){
yan3 data=new yan3();
data.cusname=tex1.getText();
data.cuspas=new String(pas.getPassword());
String toserverstr=data.cusname+ ": "+data.cuspas;
try{
Socket clientsocket;
clientsocket=new Socket( "192.168.3.56 ",8080);
getAppletContext().showStatus( "begin ");
PrintStream toserver=new PrintStream(clientsocket.getOutputStream()) ;
toserver.println( "sent! "+toserverstr);
BufferedReader fserver=new BufferedReader(new InputStreamReader(clientsocket.getInputStream()));
String message= fserver.readLine();
getAppletContext().showStatus(message);
toserver.close();
fserver.close();
}
catch(InvalidClassException e)
{
fail( "cus is error ",e);
}
catch(NotSerializableException e)
{
fail( "no string hua ",e);
}
catch(
IOException e)
{
fail( "no write to server ", e);
}
}
}
}
}
怎摸样让客户和服务端连接起来!!!!!!!!!!!!请帮我
------解决方案--------------------