socket编程!高手帮忙找一下那出问题了。急!100分!急
客户端提交的内容后,没法收到服务端发回的信息。
客户端程序:
import java.applet.*;
import java.awt.*;
import java.io.*;
import java.net.*;
import java.awt.event.*;
public class Database_client extends Applet implements Runnable ,ActionListener
{
Button b1,b2,b3;Label a,b,c,d,e,f;Panel p1,p2;TextField text,bb,cc,dd,ee,ff;
Socket scoket=null;
DataInputStream in = null;
DataOutputStream out = null;
Thread thread;
public void init()
{ //生成界面;
//setLayout(new BorderLayout());
b1=new Button( "提交 ");b2=new Button( "清除 ");b3=new Button( "退出 ");
a=new Label( "请你仔细核对所填项的数据后提交! ");
b=new Label( "用户账号 ");c=new Label( "用户密码 ");
d=new Label( "转入金额 "); e=new Label( "转入户账 ");
//f=new Label( "注意 ");
bb=new TextField(16);ee=new TextField(16);
dd=new TextField(16);cc=new TextField(16);
text=new TextField(20);
add(a);
add(b);add(bb);
add(c);add(cc);
add(d);add(dd);add(e);add(ee);
add(b1);add(b2);add(b3);add(text);
b1.addActionListener(this);b2.addActionListener(this);b3.addActionListener(this);
}
public void start()
{
try {
scoket=new Socket(this.getCodeBase().getHost(),4331);
in=new DataInputStream(scoket.getInputStream());
out=new DataOutputStream(scoket.getOutputStream());
}
catch(
IOException e){}
if(thread==null)
{
thread=new Thread(this);
//thread.setPriority(Thread.MIN_PRIORITY);
thread.start();
}
}
public void run()
{
String s=null;
while(true)
{
try
{
s=in.readUTF();
text.setText(s);
}
catch(IOException e)
{
System.out.println( "与服务器已断开! ");
text.setText( "与服务器已断开! ");
break;
}
}
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource()==b1)
{//需要把
String m=null;;//把文本框的内容都防入s中 用”,“做分界
String s1=bb.getText();String s2=cc.getText();
String s3=dd.getText();String s4=ee.getText();
m=s1+ ", "+s2+ ", "+s3+ ", "+s4;
if(m!=null)
{
try
{
out.writeUTF(m);
// out.flush();
}
catch(IOException ee){}
}
}
else if (e.getSource()==b2)
{
bb.setText(null);cc.setText(null);
dd.setText(null);ee.setText(null);
}
else if (e.getSource()==b3)
{
System.exit(0);
}
}
}
服务器端程序:
import java.io.*;
import java.net.*;
//import java.util.*;
import java.sql.*;
import java.util.StringTokenizer;
public class Database_server
{ public static void main(String args[])
{
ServerSocket server=null;
Socket you=null;
while (true)
{